From 1cc624484d2b9f38a00bd2b860fa87d068637556 Mon Sep 17 00:00:00 2001
From: Filippo Tessarotto <zoeslam@gmail.com>
Date: Fri, 16 Nov 2018 10:02:38 +0100
Subject: [PATCH 1/2] PHP 5.3 branch for legacy apps

---
 .php_cs                                       |  9 ----
 .travis.yml                                   |  4 +-
 composer.json                                 |  7 +--
 lib/r.php                                     | 48 ++++-------------
 tests/Doctrine/DebugTest.php                  | 54 ++++++-------------
 tests/Doctrine/TestAsset/ChildClass.php       |  2 -
 .../ChildWithSameAttributesClass.php          |  2 -
 tests/Doctrine/TestAsset/ParentClass.php      |  2 -
 tests/MockStderr.php                          |  2 -
 tests/RTest.php                               | 12 ++---
 10 files changed, 35 insertions(+), 107 deletions(-)
 delete mode 100644 .php_cs

diff --git a/.php_cs b/.php_cs
deleted file mode 100644
index db1b862..0000000
--- a/.php_cs
+++ /dev/null
@@ -1,9 +0,0 @@
-<?php
-
-$config = new SlamCsFixer\Config(SlamCsFixer\Config::LIB);
-$config->getFinder()
-    ->in(__DIR__ . '/lib')
-    ->in(__DIR__ . '/tests')
-;
-
-return $config;
diff --git a/.travis.yml b/.travis.yml
index 0cf5c0b..fccad15 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,9 +5,7 @@ sudo: false
 matrix:
   fast_finish: true
   include:
-    - php: 7.1
-      env: CS_CHECK=1
-    - php: 7.2
+    - php: 5.3
       env: CODE_COVERAGE=1
 
 cache:
diff --git a/composer.json b/composer.json
index b78b9e3..eb23845 100644
--- a/composer.json
+++ b/composer.json
@@ -17,12 +17,9 @@
         "classmap": ["tests/"]
     },
     "require": {
-        "php": "^7.1"
+        "php": "^5.3.3"
     },
     "require-dev": {
-        "doctrine/common": "^2.9",
-        "phpunit/phpunit": "^7.2",
-        "roave/security-advisories": "dev-master",
-        "slam/php-cs-fixer-extensions": "^1.16"
+        "phpunit/phpunit": "^4.8"
     }
 }
diff --git a/lib/r.php b/lib/r.php
index 9aa6292..ed1b912 100644
--- a/lib/r.php
+++ b/lib/r.php
@@ -1,21 +1,19 @@
 <?php
 
-declare(strict_types=1);
-
 namespace
 {
     use Slam\Debug\R as DebugR;
 
-    function r($var, bool $exit = true, int $level = 0, bool $fullstack = false): void
+    function r($var, $exit = true, $level = 0, $fullstack = false)
     {
         DebugR::$db = \debug_backtrace();
         DebugR::debug($var, $exit, $level, $fullstack);
     }
 
-    function rq(string $query, array $params, bool $exit = true, int $level = 0, bool $fullstack = false): void
+    function rq($query, array $params, $exit = true, $level = 0, $fullstack = false)
     {
-        \uksort($params, function (string $key1, string $key2) {
-            return \strlen($key2) <=> \strlen($key1);
+        \uksort($params, function ($key1, $key2) {
+            return strcmp(\strlen($key2), \strlen($key1));
         });
 
         foreach ($params as $key => $value) {
@@ -35,13 +33,13 @@ function rq(string $query, array $params, bool $exit = true, int $level = 0, boo
 {
     final class R
     {
-        public static $db = [];
+        public static $db = array();
 
         private function __construct()
         {
         }
 
-        public static function debug($var, bool $exit = true, int $level = 0, bool $fullstack = false): void
+        public static function debug($var, $exit = true, $level = 0, $fullstack = false)
         {
             if (null === $var || \is_scalar($var)) {
                 \ob_start();
@@ -64,7 +62,7 @@ public static function debug($var, bool $exit = true, int $level = 0, bool $full
             }
         }
 
-        private static function formatDb(bool $fullstack): string
+        private static function formatDb($fullstack)
         {
             $output = '';
 
@@ -75,7 +73,7 @@ private static function formatDb(bool $fullstack): string
 
                 $output .= (isset($point['class']) ? $point['class'] . '->' : '') . $point['function'];
 
-                $args = [];
+                $args = array();
                 foreach ($point['args'] as $argument) {
                     $args[] = (\is_object($argument)
                         ? \get_class($argument)
@@ -102,7 +100,6 @@ private static function formatDb(bool $fullstack): string
 namespace Slam\Debug\Doctrine
 {
     use Doctrine\Common\Collections\Collection;
-    use Doctrine\Common\Persistence\Proxy;
 
     /**
      * Static class containing most used debug methods.
@@ -173,17 +170,13 @@ public static function export($var, $maxDepth)
             $return = null;
             $isObj  = \is_object($var);
 
-            if ($var instanceof Collection) {
-                $var = $var->toArray();
-            }
-
             if (! $maxDepth) {
                 return \is_object($var) ? \get_class($var)
                     : (\is_array($var) ? 'Array(' . \count($var) . ')' : $var);
             }
 
             if (\is_array($var)) {
-                $return = [];
+                $return = array();
 
                 foreach ($var as $k => $v) {
                     $return[$k] = self::export($v, $maxDepth - 1);
@@ -207,11 +200,6 @@ public static function export($var, $maxDepth)
 
             $return->__CLASS__ = self::getClass($var);
 
-            if ($var instanceof Proxy) {
-                $return->__IS_PROXY__          = true;
-                $return->__PROXY_INITIALIZED__ = $var->__isInitialized();
-            }
-
             if ($var instanceof \ArrayObject || $var instanceof \ArrayIterator) {
                 $return->__STORAGE__ = self::export($var->getArrayCopy(), $maxDepth - 1);
             }
@@ -245,22 +233,6 @@ private static function fillReturnWithClassAttributes($var, \stdClass $return, $
             return $return;
         }
 
-        /**
-         * Gets the real class name of a class name that could be a proxy.
-         *
-         * @param string $class
-         *
-         * @return string
-         */
-        private static function getRealClass($class)
-        {
-            if (! \class_exists(Proxy::class) || false === ($pos = \strrpos($class, '\\' . Proxy::MARKER . '\\'))) {
-                return $class;
-            }
-
-            return \substr($class, $pos + Proxy::MARKER_LENGTH + 2);
-        }
-
         /**
          * Gets the real class name of an object (even if its a proxy).
          *
@@ -270,7 +242,7 @@ private static function getRealClass($class)
          */
         private static function getClass($object)
         {
-            return self::getRealClass(\get_class($object));
+            return \get_class($object);
         }
     }
 }
diff --git a/tests/Doctrine/DebugTest.php b/tests/Doctrine/DebugTest.php
index 691679f..6121b94 100644
--- a/tests/Doctrine/DebugTest.php
+++ b/tests/Doctrine/DebugTest.php
@@ -1,13 +1,11 @@
 <?php
 
-declare(strict_types=1);
-
 namespace SlamTest\Debug\Doctrine;
 
-use PHPUnit\Framework\TestCase;
+use PHPUnit_Framework_TestCase;
 use Slam\Debug\Doctrine\Debug;
 
-final class DebugTest extends TestCase
+final class DebugTest extends PHPUnit_Framework_TestCase
 {
     public function testExportObject()
     {
@@ -22,7 +20,7 @@ public function testExportObject()
     public function testExportObjectWithReference()
     {
         $foo = 'bar';
-        $bar = ['foo' => & $foo];
+        $bar = array('foo' => & $foo);
         $baz = (object) $bar;
 
         $var      = Debug::export($baz, 2);
@@ -34,7 +32,7 @@ public function testExportObjectWithReference()
 
     public function testExportArray()
     {
-        $array              = ['a' => 'b', 'b' => ['c', 'd' => ['e', 'f']]];
+        $array              = array('a' => 'b', 'b' => array('c', 'd' => array('e', 'f')));
         $var                = Debug::export($array, 2);
         $expected           = $array;
         $expected['b']['d'] = 'Array(2)';
@@ -47,35 +45,17 @@ public function testExportDateTime()
 
         $var = Debug::export($obj, 2);
         static::assertEquals('DateTime', $var->__CLASS__);
-        static::assertEquals('2010-10-10T10:10:10+00:00', $var->date);
-    }
-
-    public function testExportDateTimeImmutable()
-    {
-        $obj = new \DateTimeImmutable('2010-10-10 10:10:10', new \DateTimeZone('UTC'));
-
-        $var = Debug::export($obj, 2);
-        static::assertEquals('DateTimeImmutable', $var->__CLASS__);
-        static::assertEquals('2010-10-10T10:10:10+00:00', $var->date);
-    }
-
-    public function testExportDateTimeZone()
-    {
-        $obj = new \DateTimeImmutable('2010-10-10 12:34:56', new \DateTimeZone('Europe/Rome'));
-
-        $var = Debug::export($obj, 2);
-        static::assertEquals('DateTimeImmutable', $var->__CLASS__);
-        static::assertEquals('2010-10-10T12:34:56+02:00', $var->date);
+        static::assertEquals('2010-10-10 10:10:10', $var->date);
     }
 
     public function testExportArrayTraversable()
     {
-        $obj = new \ArrayObject(['foobar']);
+        $obj = new \ArrayObject(array('foobar'));
 
         $var = Debug::export($obj, 2);
         static::assertContains('foobar', $var->__STORAGE__);
 
-        $it = new \ArrayIterator(['foobar']);
+        $it = new \ArrayIterator(array('foobar'));
 
         $var = Debug::export($it, 5);
         static::assertContains('foobar', $var->__STORAGE__);
@@ -128,27 +108,27 @@ public function testExportParentAttributes(TestAsset\ParentClass $class, array $
 
     public function provideAttributesCases()
     {
-        return [
-            'different-attributes' => [
+        return array(
+            'different-attributes' => array(
                 new TestAsset\ChildClass(),
-                [
+                array(
                     'childPublicAttribute'                                                         => 4,
                     'childProtectedAttribute:protected'                                            => 5,
                     'childPrivateAttribute:SlamTest\Debug\Doctrine\TestAsset\ChildClass:private'   => 6,
                     'parentPublicAttribute'                                                        => 1,
                     'parentProtectedAttribute:protected'                                           => 2,
                     'parentPrivateAttribute:SlamTest\Debug\Doctrine\TestAsset\ParentClass:private' => 3,
-                ],
-            ],
-            'same-attributes' => [
+                ),
+            ),
+            'same-attributes' => array(
                 new TestAsset\ChildWithSameAttributesClass(),
-                [
+                array(
                     'parentPublicAttribute'                                                                         => 4,
                     'parentProtectedAttribute:protected'                                                            => 5,
                     'parentPrivateAttribute:SlamTest\Debug\Doctrine\TestAsset\ChildWithSameAttributesClass:private' => 6,
                     'parentPrivateAttribute:SlamTest\Debug\Doctrine\TestAsset\ParentClass:private'                  => 3,
-                ],
-            ],
-        ];
+                ),
+            ),
+        );
     }
 }
diff --git a/tests/Doctrine/TestAsset/ChildClass.php b/tests/Doctrine/TestAsset/ChildClass.php
index 40a03b3..c3a7af5 100644
--- a/tests/Doctrine/TestAsset/ChildClass.php
+++ b/tests/Doctrine/TestAsset/ChildClass.php
@@ -1,7 +1,5 @@
 <?php
 
-declare(strict_types=1);
-
 namespace SlamTest\Debug\Doctrine\TestAsset;
 
 final class ChildClass extends ParentClass
diff --git a/tests/Doctrine/TestAsset/ChildWithSameAttributesClass.php b/tests/Doctrine/TestAsset/ChildWithSameAttributesClass.php
index aa89146..7d1c976 100644
--- a/tests/Doctrine/TestAsset/ChildWithSameAttributesClass.php
+++ b/tests/Doctrine/TestAsset/ChildWithSameAttributesClass.php
@@ -1,7 +1,5 @@
 <?php
 
-declare(strict_types=1);
-
 namespace SlamTest\Debug\Doctrine\TestAsset;
 
 final class ChildWithSameAttributesClass extends ParentClass
diff --git a/tests/Doctrine/TestAsset/ParentClass.php b/tests/Doctrine/TestAsset/ParentClass.php
index 62227fd..d5eef1f 100644
--- a/tests/Doctrine/TestAsset/ParentClass.php
+++ b/tests/Doctrine/TestAsset/ParentClass.php
@@ -1,7 +1,5 @@
 <?php
 
-declare(strict_types=1);
-
 namespace SlamTest\Debug\Doctrine\TestAsset;
 
 abstract class ParentClass
diff --git a/tests/MockStderr.php b/tests/MockStderr.php
index 3f5cf07..423b5a1 100644
--- a/tests/MockStderr.php
+++ b/tests/MockStderr.php
@@ -1,7 +1,5 @@
 <?php
 
-declare(strict_types=1);
-
 namespace SlamTest\Debug;
 
 use php_user_filter;
diff --git a/tests/RTest.php b/tests/RTest.php
index ba0e8ca..c671708 100644
--- a/tests/RTest.php
+++ b/tests/RTest.php
@@ -1,13 +1,11 @@
 <?php
 
-declare(strict_types=1);
-
 namespace SlamTest\Debug;
 
-use PHPUnit\Framework\TestCase;
+use PHPUnit_Framework_TestCase;
 use stdClass;
 
-final class RTest extends TestCase
+final class RTest extends PHPUnit_Framework_TestCase
 {
     const STREAM_FILTER_NAME = 'STDERR_MOCK';
 
@@ -18,7 +16,7 @@ final class RTest extends TestCase
     protected function setUp()
     {
         if (true !== self::$isStreamFilterRegistered) {
-            self::$isStreamFilterRegistered = \stream_filter_register(self::STREAM_FILTER_NAME, MockStderr::class);
+            self::$isStreamFilterRegistered = \stream_filter_register(self::STREAM_FILTER_NAME, 'SlamTest\\Debug\\MockStderr');
         }
 
         MockStderr::$output     = '';
@@ -40,7 +38,7 @@ public function testScalar()
 
     public function testNonScalar()
     {
-        r([1 => 2], false);
+        r(array(1 => 2), false);
 
         static::assertContains(__FILE__, MockStderr::$output);
         static::assertContains("Array\n(\n    [1] => 2\n)", MockStderr::$output);
@@ -57,7 +55,7 @@ public function testFullstackOutput()
 
     public function testQueryDebug()
     {
-        rq('SELECT * FROM table WHERE c1 = :p1 AND c1 = :p11 AND c1 = :p2', ['p1' => 1, 'p11' => 2, 'p2' => '"'], false, 0, true);
+        rq('SELECT * FROM table WHERE c1 = :p1 AND c1 = :p11 AND c1 = :p2', array('p1' => 1, 'p11' => 2, 'p2' => '"'), false, 0, true);
 
         static::assertContains('SELECT * FROM table WHERE c1 = "1" AND c1 = "2" AND c1 = "\\""', MockStderr::$output);
     }

From 16804c7c2ad7ba93915a90a83e1b789cdac60ef6 Mon Sep 17 00:00:00 2001
From: Filippo Tessarotto <zoeslam@gmail.com>
Date: Fri, 16 Nov 2018 10:06:31 +0100
Subject: [PATCH 2/2] Need precise on Travis for PHP 5.3

---
 .travis.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.travis.yml b/.travis.yml
index fccad15..a5ce989 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,6 +6,7 @@ matrix:
   fast_finish: true
   include:
     - php: 5.3
+      dist: precise
       env: CODE_COVERAGE=1
 
 cache:
