From 879771170e3a6e24e73560e05842a42c497662aa Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 1 Aug 2015 09:16:55 +0200 Subject: [PATCH] Remove code for PHP <5.5.9 --- .../PhpUnit/DeprecationErrorHandler.php | 2 +- .../Bridge/Twig/Command/LintCommand.php | 2 +- .../Command/YamlLintCommand.php | 2 +- .../Console/Descriptor/JsonDescriptor.php | 7 +--- .../ClassLoader/ClassCollectionLoader.php | 10 ++--- .../Component/Console/Command/Command.php | 2 +- .../Console/Tests/Command/CommandTest.php | 4 -- .../Tests/ContainerTest.php | 4 +- .../DateTimeToArrayTransformerTest.php | 4 -- ...teTimeToLocalizedStringTransformerTest.php | 4 -- .../DateTimeToRfc3339TransformerTest.php | 4 -- .../DateTimeToStringTransformerTest.php | 4 -- .../DateTimeToTimestampTransformerTest.php | 4 -- .../Component/HttpFoundation/JsonResponse.php | 37 +++---------------- .../Component/HttpFoundation/Response.php | 1 + .../DataCollector/DumpDataCollector.php | 2 +- .../DataCollector/DumpDataCollectorTest.php | 25 ++----------- .../Session/SessionAuthenticationStrategy.php | 5 +-- .../SessionAuthenticationStrategyTest.php | 17 --------- 19 files changed, 21 insertions(+), 119 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index 42d88b030d..36661f3637 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -40,7 +40,7 @@ class DeprecationErrorHandler return \PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context); } - $trace = debug_backtrace(PHP_VERSION_ID >= 50400 ? DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT : true); + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); $i = count($trace); while (isset($trace[--$i]['class']) && ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_'))) { diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index 04bcea2b43..dbf08a9e52 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -196,7 +196,7 @@ EOF } }); - $output->writeln(json_encode($filesInfo, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0)); + $output->writeln(json_encode($filesInfo, JSON_PRETTY_PRINT); return min($errors, 1); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/YamlLintCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/YamlLintCommand.php index 223f186193..d44f0c5ffb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/YamlLintCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/YamlLintCommand.php @@ -152,7 +152,7 @@ EOF } }); - $output->writeln(json_encode($filesInfo, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0)); + $output->writeln(json_encode($filesInfo, JSON_PRETTY_PRINT); return min($errors, 1); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php index c4121cfa3f..307a8e082a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php @@ -171,12 +171,7 @@ class JsonDescriptor extends Descriptor private function writeData(array $data, array $options) { $flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0; - - if (defined('JSON_PRETTY_PRINT')) { - $flags |= JSON_PRETTY_PRINT; - } - - $this->write(json_encode($data, $flags)."\n"); + $this->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n"); } /** diff --git a/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php b/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php index 8627516526..2b4c83eafb 100644 --- a/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php +++ b/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php @@ -280,12 +280,10 @@ class ClassCollectionLoader $traits = array(); - if (function_exists('get_declared_traits')) { - foreach ($classes as $c) { - foreach (self::resolveDependencies(self::computeTraitDeps($c), $c) as $trait) { - if ($trait !== $c) { - $traits[] = $trait; - } + foreach ($classes as $c) { + foreach (self::resolveDependencies(self::computeTraitDeps($c), $c) as $trait) { + if ($trait !== $c) { + $traits[] = $trait; } } } diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index ca2bb8a265..7fc5862557 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -281,7 +281,7 @@ class Command throw new \InvalidArgumentException('Invalid callable provided to Command::setCode.'); } - if (PHP_VERSION_ID >= 50400 && $code instanceof \Closure) { + if ($code instanceof \Closure) { $r = new \ReflectionFunction($code); if (null === $r->getClosureThis()) { $code = \Closure::bind($code, $this); diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index 82115f9b6d..980486981e 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -295,10 +295,6 @@ class CommandTest extends \PHPUnit_Framework_TestCase /** @dataProvider getSetCodeBindToClosureTests */ public function testSetCodeBindToClosure($previouslyBound, $expected) { - if (PHP_VERSION_ID < 50400) { - $this->markTestSkipped('Test skipped, for PHP 5.4+ only.'); - } - $code = createClosure(); if ($previouslyBound) { $code = $code->bindTo($this); diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index cd40d71d11..c0dbc5b821 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -698,9 +698,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { $class = new \ReflectionClass('Symfony\Component\DependencyInjection\Container'); $clone = $class->getMethod('__clone'); - if (PHP_VERSION_ID >= 540000) { - $this->assertFalse($class->isCloneable()); - } + $this->assertFalse($class->isCloneable()); $this->assertTrue($clone->isPrivate()); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToArrayTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToArrayTransformerTest.php index 3042eea5a4..7b81f4775c 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToArrayTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToArrayTransformerTest.php @@ -118,10 +118,6 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase public function testTransformDateTimeImmutable() { - if (PHP_VERSION_ID < 50500) { - $this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0'); - } - $transformer = new DateTimeToArrayTransformer('America/New_York', 'Asia/Hong_Kong'); $input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York'); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php index d6964d395a..0ae906b064 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php @@ -143,10 +143,6 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase public function testTransformDateTimeImmutableTimezones() { - if (PHP_VERSION_ID < 50500) { - $this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0'); - } - $transformer = new DateTimeToLocalizedStringTransformer('America/New_York', 'Asia/Hong_Kong'); $input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York'); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php index be3827cc74..7e9c2e30c9 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php @@ -84,10 +84,6 @@ class DateTimeToRfc3339TransformerTest extends DateTimeTestCase */ public function testTransformDateTimeImmutable($fromTz, $toTz, $from, $to) { - if (PHP_VERSION_ID < 50500) { - $this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0'); - } - $transformer = new DateTimeToRfc3339Transformer($fromTz, $toTz); $this->assertSame($to, $transformer->transform(null !== $from ? new \DateTimeImmutable($from) : null)); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php index ffe8a1daf1..3d7d042f2d 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php @@ -97,10 +97,6 @@ class DateTimeToStringTransformerTest extends DateTimeTestCase public function testTransformDateTimeImmutable() { - if (PHP_VERSION_ID < 50500) { - $this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0'); - } - $transformer = new DateTimeToStringTransformer('Asia/Hong_Kong', 'America/New_York', 'Y-m-d H:i:s'); $input = new \DateTimeImmutable('2010-02-03 12:05:06 America/New_York'); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php index 451451d09d..8f05303801 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php @@ -58,10 +58,6 @@ class DateTimeToTimestampTransformerTest extends DateTimeTestCase public function testTransformDateTimeImmutable() { - if (PHP_VERSION_ID < 50500) { - $this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0'); - } - $transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York'); $input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York'); diff --git a/src/Symfony/Component/HttpFoundation/JsonResponse.php b/src/Symfony/Component/HttpFoundation/JsonResponse.php index 0445a9a6ce..075e500ba2 100644 --- a/src/Symfony/Component/HttpFoundation/JsonResponse.php +++ b/src/Symfony/Component/HttpFoundation/JsonResponse.php @@ -102,39 +102,12 @@ class JsonResponse extends Response $data = json_encode($data, $this->encodingOptions); } else { try { - if (PHP_VERSION_ID < 50400) { - // PHP 5.3 triggers annoying warnings for some - // types that can't be serialized as JSON (INF, resources, etc.) - // but doesn't provide the JsonSerializable interface. - set_error_handler('var_dump', 0); - $data = @json_encode($data, $this->encodingOptions); - } else { - // PHP 5.4 and up wrap exceptions thrown by JsonSerializable - // objects in a new exception that needs to be removed. - // Fortunately, PHP 5.5 and up do not trigger any warning anymore. - if (PHP_VERSION_ID < 50500) { - // Clear json_last_error() - json_encode(null); - $errorHandler = set_error_handler('var_dump'); - restore_error_handler(); - set_error_handler(function () use ($errorHandler) { - if (JSON_ERROR_NONE === json_last_error()) { - return $errorHandler && false !== call_user_func_array($errorHandler, func_get_args()); - } - }); - } - - $data = json_encode($data, $this->encodingOptions); - } - - if (PHP_VERSION_ID < 50500) { - restore_error_handler(); - } + // PHP 5.4 and up wrap exceptions thrown by JsonSerializable + // objects in a new exception that needs to be removed. + // Fortunately, PHP 5.5 and up do not trigger any warning anymore. + $data = json_encode($data, $this->encodingOptions); } catch (\Exception $e) { - if (PHP_VERSION_ID < 50500) { - restore_error_handler(); - } - if (PHP_VERSION_ID >= 50400 && 'Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) { + if ('Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) { throw $e->getPrevious() ?: $e; } throw $e; diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 9f8c7ef292..b23ac16b06 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -1247,6 +1247,7 @@ class Response { $status = ob_get_status(true); $level = count($status); + // PHP_OUTPUT_HANDLER_* are not defined on HHVM 3.3 $flags = defined('PHP_OUTPUT_HANDLER_REMOVABLE') ? PHP_OUTPUT_HANDLER_REMOVABLE | ($flush ? PHP_OUTPUT_HANDLER_FLUSHABLE : PHP_OUTPUT_HANDLER_CLEANABLE) : -1; while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || $flags === ($s['flags'] & $flags) : $s['del'])) { diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php index ffbeaf8f73..02deae3f10 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php @@ -247,7 +247,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface private function doDump($data, $name, $file, $line) { - if (PHP_VERSION_ID >= 50400 && $this->dumper instanceof CliDumper) { + if ($this->dumper instanceof CliDumper) { $contextDumper = function ($name, $file, $line, $fileLinkFormat) { if ($this instanceof HtmlDumper) { if ('' !== $file) { diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php index 4e7ae4e769..a607d279db 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php @@ -71,11 +71,7 @@ class DumpDataCollectorTest extends \PHPUnit_Framework_TestCase $collector->collect(new Request(), new Response()); $output = ob_get_clean(); - if (PHP_VERSION_ID >= 50400) { - $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output); - } else { - $this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n123\n", $output); - } + $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output); $this->assertSame(1, $collector->getDumpsCount()); $collector->serialize(); } @@ -89,23 +85,12 @@ class DumpDataCollectorTest extends \PHPUnit_Framework_TestCase $collector->dump($data); $line = __LINE__ - 1; $file = __FILE__; - if (PHP_VERSION_ID >= 50400) { - $xOutput = <<DumpDataCollectorTest.php on line {$line}: 123 EOTXT; - } else { - $len = strlen("DumpDataCollectorTest.php on line {$line}:"); - $xOutput = <<"DumpDataCollectorTest.php on line {$line}:" - -
123
-
- -EOTXT; - } ob_start(); $response = new Response(); @@ -129,10 +114,6 @@ EOTXT; ob_start(); $collector = null; - if (PHP_VERSION_ID >= 50400) { - $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean()); - } else { - $this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", ob_get_clean()); - } + $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean()); } } diff --git a/src/Symfony/Component/Security/Http/Session/SessionAuthenticationStrategy.php b/src/Symfony/Component/Security/Http/Session/SessionAuthenticationStrategy.php index ccfa6ba67a..dd258a086f 100644 --- a/src/Symfony/Component/Security/Http/Session/SessionAuthenticationStrategy.php +++ b/src/Symfony/Component/Security/Http/Session/SessionAuthenticationStrategy.php @@ -47,10 +47,7 @@ class SessionAuthenticationStrategy implements SessionAuthenticationStrategyInte return; case self::MIGRATE: - // Destroying the old session is broken in php 5.4.0 - 5.4.10 - // See php bug #63379 - $destroy = PHP_VERSION_ID < 50400 || PHP_VERSION_ID >= 50411; - $request->getSession()->migrate($destroy); + $request->getSession()->migrate(true); return; diff --git a/src/Symfony/Component/Security/Http/Tests/Session/SessionAuthenticationStrategyTest.php b/src/Symfony/Component/Security/Http/Tests/Session/SessionAuthenticationStrategyTest.php index 4aef4b203b..a1f960fde4 100644 --- a/src/Symfony/Component/Security/Http/Tests/Session/SessionAuthenticationStrategyTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Session/SessionAuthenticationStrategyTest.php @@ -39,10 +39,6 @@ class SessionAuthenticationStrategyTest extends \PHPUnit_Framework_TestCase public function testSessionIsMigrated() { - if (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID < 50411) { - $this->markTestSkipped('We cannot destroy the old session on PHP 5.4.0 - 5.4.10.'); - } - $session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface'); $session->expects($this->once())->method('migrate')->with($this->equalTo(true)); @@ -50,19 +46,6 @@ class SessionAuthenticationStrategyTest extends \PHPUnit_Framework_TestCase $strategy->onAuthentication($this->getRequest($session), $this->getToken()); } - public function testSessionIsMigratedWithPhp54Workaround() - { - if (PHP_VERSION_ID < 50400 || PHP_VERSION_ID >= 50411) { - $this->markTestSkipped('This PHP version is not affected.'); - } - - $session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface'); - $session->expects($this->once())->method('migrate')->with($this->equalTo(false)); - - $strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE); - $strategy->onAuthentication($this->getRequest($session), $this->getToken()); - } - public function testSessionIsInvalidated() { $session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');