Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7091fb4

Browse files
ogizanaginicolas-grekas
authored andcommitted
Remove PHP < 7.1.3 code
1 parent 619f01c commit 7091fb4

File tree

69 files changed

+119
-567
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+119
-567
lines changed

src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ public function getHtmlCallGraph()
9393
public function getProfile()
9494
{
9595
if (null === $this->profile) {
96-
if (PHP_VERSION_ID >= 70000) {
97-
$this->profile = unserialize($this->data['profile'], array('allowed_classes' => array('Twig_Profiler_Profile')));
98-
} else {
99-
$this->profile = unserialize($this->data['profile']);
100-
}
96+
$this->profile = unserialize($this->data['profile'], array('allowed_classes' => array('Twig_Profiler_Profile')));
10197
}
10298

10399
return $this->profile;

src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ public function testOneVar()
8282

8383
EOTXT;
8484

85-
if (PHP_VERSION_ID >= 70000) {
86-
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
87-
} else {
88-
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
89-
}
85+
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
9086

9187
$this->assertSame($expected, $compiler->compile($node)->getSource());
9288
}
@@ -113,11 +109,7 @@ public function testMultiVars()
113109

114110
EOTXT;
115111

116-
if (PHP_VERSION_ID >= 70000) {
117-
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
118-
} else {
119-
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
120-
}
112+
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
121113

122114
$this->assertSame($expected, $compiler->compile($node)->getSource());
123115
}

src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ public function testCompile()
6767

6868
protected function getVariableGetter($name)
6969
{
70-
if (PHP_VERSION_ID >= 70000) {
71-
return sprintf('($context["%s"] ?? null)', $name, $name);
72-
}
73-
74-
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
70+
return sprintf('($context["%s"] ?? null)', $name, $name);
7571
}
7672
}

src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,6 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
264264

265265
protected function getVariableGetter($name)
266266
{
267-
if (PHP_VERSION_ID >= 70000) {
268-
return sprintf('($context["%s"] ?? null)', $name, $name);
269-
}
270-
271-
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
267+
return sprintf('($context["%s"] ?? null)', $name, $name);
272268
}
273269
}

src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ public function testCompileStrict()
4040

4141
protected function getVariableGetterWithoutStrictCheck($name)
4242
{
43-
if (PHP_VERSION_ID >= 70000) {
44-
return sprintf('($context["%s"] ?? null)', $name, $name);
45-
}
46-
47-
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
43+
return sprintf('($context["%s"] ?? null)', $name, $name);
4844
}
4945

5046
protected function getVariableGetterWithStrictCheck($name)
@@ -53,10 +49,6 @@ protected function getVariableGetterWithStrictCheck($name)
5349
return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : (function () { throw new Twig_Error_Runtime(\'Variable "%s" does not exist.\', 0, $this->getSourceContext()); })())', $name, $name, $name, $name);
5450
}
5551

56-
if (PHP_VERSION_ID >= 70000) {
57-
return sprintf('($context["%s"] ?? $this->getContext($context, "%s"))', $name, $name, $name);
58-
}
59-
60-
return sprintf('(isset($context["%s"]) ? $context["%s"] : $this->getContext($context, "%s"))', $name, $name, $name);
52+
return sprintf('($context["%s"] ?? $this->getContext($context, "%s"))', $name, $name, $name);
6153
}
6254
}

src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ public function extract($resource, MessageCatalogue $catalog)
8585
foreach ($files as $file) {
8686
$this->parseTokens(token_get_all(file_get_contents($file)), $catalog);
8787

88-
if (PHP_VERSION_ID >= 70000) {
89-
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
90-
gc_mem_caches();
91-
}
88+
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
89+
gc_mem_caches();
9290
}
9391
}
9492

src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,17 @@ function ($key, $value, $isHit) {
5353
}
5454

5555
/**
56-
* This adapter should only be used on PHP 7.0+ to take advantage of how PHP
57-
* stores arrays in its latest versions. This factory method decorates the given
58-
* fallback pool with this adapter only if the current PHP version is supported.
56+
* This adapter to take advantage of how PHP stores arrays in its latest versions.
5957
*
6058
* @param string $file The PHP file were values are cached
61-
* @param CacheItemPoolInterface $fallbackPool Fallback for old PHP versions or opcache disabled
59+
* @param CacheItemPoolInterface $fallbackPool Fallback when opcache is disabled
6260
*
6361
* @return CacheItemPoolInterface
6462
*/
6563
public static function create($file, CacheItemPoolInterface $fallbackPool)
6664
{
6765
// Shared memory is available in PHP 7.0+ with OPCache enabled and in HHVM
68-
if ((PHP_VERSION_ID >= 70000 && ini_get('opcache.enable')) || defined('HHVM_VERSION')) {
66+
if (ini_get('opcache.enable') || defined('HHVM_VERSION')) {
6967
if (!$fallbackPool instanceof AdapterInterface) {
7068
$fallbackPool = new ProxyAdapter($fallbackPool);
7169
}

src/Symfony/Component/Cache/Simple/PhpArrayCache.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ public function __construct($file, CacheInterface $fallbackPool)
3737
}
3838

3939
/**
40-
* This adapter should only be used on PHP 7.0+ to take advantage of how PHP
41-
* stores arrays in its latest versions. This factory method decorates the given
42-
* fallback pool with this adapter only if the current PHP version is supported.
40+
* This adapter to take advantage of how PHP stores arrays in its latest versions.
4341
*
4442
* @param string $file The PHP file were values are cached
4543
*
@@ -48,7 +46,7 @@ public function __construct($file, CacheInterface $fallbackPool)
4846
public static function create($file, CacheInterface $fallbackPool)
4947
{
5048
// Shared memory is available in PHP 7.0+ with OPCache enabled and in HHVM
51-
if ((PHP_VERSION_ID >= 70000 && ini_get('opcache.enable')) || defined('HHVM_VERSION')) {
49+
if (ini_get('opcache.enable') || defined('HHVM_VERSION')) {
5250
return new static($file, $fallbackPool);
5351
}
5452

src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,8 @@ public function provideHashedSignature()
124124
yield array(0, 8, '/** priv docblock */');
125125
yield array(0, 9, 'private $priv = 123;');
126126
yield array(1, 10, '/** pub docblock */');
127-
if (PHP_VERSION_ID >= 50600) {
128-
yield array(1, 11, 'public function pub(...$arg) {}');
129-
}
130-
if (PHP_VERSION_ID >= 70000) {
131-
yield array(1, 11, 'public function pub($arg = null): Foo {}');
132-
}
127+
yield array(1, 11, 'public function pub(...$arg) {}');
128+
yield array(1, 11, 'public function pub($arg = null): Foo {}');
133129
yield array(0, 11, "public function pub(\$arg = null) {\nreturn 123;\n}");
134130
yield array(1, 12, '/** prot docblock */');
135131
yield array(1, 13, 'protected function prot($a = array(123)) {}');

src/Symfony/Component/Console/Command/Command.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,7 @@ public function setCode(callable $code)
286286
if ($code instanceof \Closure) {
287287
$r = new \ReflectionFunction($code);
288288
if (null === $r->getClosureThis()) {
289-
if (PHP_VERSION_ID < 70000) {
290-
// Bug in PHP5: https://bugs.php.net/bug.php?id=64761
291-
// This means that we cannot bind static closures and therefore we must
292-
// ignore any errors here. There is no way to test if the closure is
293-
// bindable.
294-
$code = @\Closure::bind($code, $this);
295-
} else {
296-
$code = \Closure::bind($code, $this);
297-
}
289+
$code = \Closure::bind($code, $this);
298290
}
299291
}
300292

src/Symfony/Component/Console/Input/ArgvInput.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,6 @@ private function parseLongOption($token)
148148

149149
if (false !== $pos = strpos($name, '=')) {
150150
if (0 === strlen($value = substr($name, $pos + 1))) {
151-
// if no value after "=" then substr() returns "" since php7 only, false before
152-
// see http://php.net/manual/fr/migration70.incompatible.php#119151
153-
if (PHP_VERSION_ID < 70000 && false === $value) {
154-
$value = '';
155-
}
156151
array_unshift($this->parsed, $value);
157152
}
158153
$this->addLongOption(substr($name, 0, $pos), $value);

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,9 +1106,6 @@ public function testConsoleErrorEventIsTriggeredOnCommandNotFound()
11061106
$this->assertEquals(1, $tester->getStatusCode());
11071107
}
11081108

1109-
/**
1110-
* @requires PHP 7
1111-
*/
11121109
public function testErrorIsRethrownIfNotHandledByConsoleErrorEvent()
11131110
{
11141111
$application = new Application();
@@ -1342,9 +1339,6 @@ protected function getDispatcher($skipCommand = false)
13421339
return $dispatcher;
13431340
}
13441341

1345-
/**
1346-
* @requires PHP 7
1347-
*/
13481342
public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEnabled()
13491343
{
13501344
$application = new Application();

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,7 @@ public function testSetCodeWithStaticClosure()
392392
$tester = new CommandTester($command);
393393
$tester->execute(array());
394394

395-
if (PHP_VERSION_ID < 70000) {
396-
// Cannot bind static closures in PHP 5
397-
$this->assertEquals('interact called'.PHP_EOL.'not bound'.PHP_EOL, $tester->getDisplay());
398-
} else {
399-
// Can bind static closures in PHP 7
400-
$this->assertEquals('interact called'.PHP_EOL.'bound'.PHP_EOL, $tester->getDisplay());
401-
}
395+
$this->assertEquals('interact called'.PHP_EOL.'bound'.PHP_EOL, $tester->getDisplay());
402396
}
403397

404398
private static function createClosure()

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class DebugClassLoader
3030
private static $final = array();
3131
private static $finalMethods = array();
3232
private static $deprecated = array();
33-
private static $php7Reserved = array('int', 'float', 'bool', 'string', 'true', 'false', 'null');
3433
private static $darwinCache = array('/' => array('/', array()));
3534

3635
/**
@@ -201,9 +200,7 @@ public function loadClass($class)
201200
}
202201
}
203202

204-
if (in_array(strtolower($refl->getShortName()), self::$php7Reserved)) {
205-
@trigger_error(sprintf('The "%s" class uses the reserved name "%s", it will break on PHP 7 and higher', $name, $refl->getShortName()), E_USER_DEPRECATED);
206-
} elseif (preg_match('#\n \* @deprecated (.*?)\r?\n \*(?: @|/$)#s', $refl->getDocComment(), $notice)) {
203+
if (preg_match('#\n \* @deprecated (.*?)\r?\n \*(?: @|/$)#s', $refl->getDocComment(), $notice)) {
207204
self::$deprecated[$name] = preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]);
208205
} else {
209206
// Don't trigger deprecations for classes in the same vendor

src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,6 @@ public function testIdempotence()
5959
$this->fail('DebugClassLoader did not register');
6060
}
6161

62-
public function testUnsilencing()
63-
{
64-
if (PHP_VERSION_ID >= 70000) {
65-
$this->markTestSkipped('PHP7 throws exceptions, unsilencing is not required anymore.');
66-
}
67-
if (defined('HHVM_VERSION')) {
68-
$this->markTestSkipped('HHVM is not handled in this test case.');
69-
}
70-
71-
ob_start();
72-
73-
$this->iniSet('log_errors', 0);
74-
$this->iniSet('display_errors', 1);
75-
76-
// See below: this will fail with parse error
77-
// but this should not be @-silenced.
78-
@class_exists(__NAMESPACE__.'\TestingUnsilencing', true);
79-
80-
$output = ob_get_clean();
81-
82-
$this->assertStringMatchesFormat('%aParse error%a', $output);
83-
}
84-
8562
public function testStacking()
8663
{
8764
// the ContextErrorException must not be loaded to test the workaround
@@ -109,13 +86,8 @@ class ChildTestingStacking extends TestingStacking { function foo($bar) {} }
10986
} catch (\ErrorException $exception) {
11087
// if an exception is thrown, the test passed
11188
$this->assertStringStartsWith(__FILE__, $exception->getFile());
112-
if (PHP_VERSION_ID < 70000) {
113-
$this->assertRegExp('/^Runtime Notice: Declaration/', $exception->getMessage());
114-
$this->assertEquals(E_STRICT, $exception->getSeverity());
115-
} else {
116-
$this->assertRegExp('/^Warning: Declaration/', $exception->getMessage());
117-
$this->assertEquals(E_WARNING, $exception->getSeverity());
118-
}
89+
$this->assertRegExp('/^Warning: Declaration/', $exception->getMessage());
90+
$this->assertEquals(E_WARNING, $exception->getSeverity());
11991
} finally {
12092
restore_error_handler();
12193
restore_exception_handler();
@@ -243,32 +215,6 @@ class_exists('Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent', true
243215
$this->assertSame($xError, $lastError);
244216
}
245217

246-
public function testReservedForPhp7()
247-
{
248-
if (PHP_VERSION_ID >= 70000) {
249-
$this->markTestSkipped('PHP7 already prevents using reserved names.');
250-
}
251-
252-
set_error_handler(function () { return false; });
253-
$e = error_reporting(0);
254-
trigger_error('', E_USER_NOTICE);
255-
256-
class_exists('Test\\'.__NAMESPACE__.'\\Float', true);
257-
258-
error_reporting($e);
259-
restore_error_handler();
260-
261-
$lastError = error_get_last();
262-
unset($lastError['file'], $lastError['line']);
263-
264-
$xError = array(
265-
'type' => E_USER_DEPRECATED,
266-
'message' => 'The "Test\Symfony\Component\Debug\Tests\Float" class uses the reserved name "Float", it will break on PHP 7 and higher',
267-
);
268-
269-
$this->assertSame($xError, $lastError);
270-
}
271-
272218
public function testExtendedFinalClass()
273219
{
274220
set_error_handler(function () { return false; });

src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,6 @@ public function testHandleFatalError()
475475
}
476476
}
477477

478-
/**
479-
* @requires PHP 7
480-
*/
481478
public function testHandleErrorException()
482479
{
483480
$exception = new \Error("Class 'Foo' not found");

src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ public function testPrevious(\Exception $exception, $statusCode)
138138
$this->assertSame(array($flattened2), $flattened->getAllPrevious());
139139
}
140140

141-
/**
142-
* @requires PHP 7.0
143-
*/
144141
public function testPreviousError()
145142
{
146143
$exception = new \Exception('test', 123, new \ParseError('Oh noes!', 42));

src/Symfony/Component/DependencyInjection/Config/AutowireServiceResource.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ public function serialize()
6565

6666
public function unserialize($serialized)
6767
{
68-
if (PHP_VERSION_ID >= 70000) {
69-
list($this->class, $this->filePath, $this->autowiringMetadata) = unserialize($serialized, array('allowed_classes' => false));
70-
} else {
71-
list($this->class, $this->filePath, $this->autowiringMetadata) = unserialize($serialized);
72-
}
68+
list($this->class, $this->filePath, $this->autowiringMetadata) = unserialize($serialized, array('allowed_classes' => false));
7369
}
7470

7571
/**

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,13 +1409,14 @@ private function dumpValue($value, $interpolate = true)
14091409
$value = $value->getValues()[0];
14101410
$code = $this->dumpValue($value, $interpolate);
14111411

1412+
$returnedType = '';
14121413
if ($value instanceof TypedReference) {
1413-
$code = sprintf('$f = function (\\%s $v%s) { return $v; }; return $f(%s);', $value->getType(), ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $value->getInvalidBehavior() ? ' = null' : '', $code);
1414-
} else {
1415-
$code = sprintf('return %s;', $code);
1414+
$returnedType = sprintf(': %s\%s', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior() ? '' : '?', $value->getType());
14161415
}
14171416

1418-
return sprintf("function () {\n %s\n }", $code);
1417+
$code = sprintf('return %s;', $code);
1418+
1419+
return sprintf("function ()%s {\n %s\n }", $returnedType, $code);
14191420
}
14201421

14211422
if ($value instanceof IteratorArgument) {
@@ -1628,9 +1629,7 @@ private function getServiceCall($id, Reference $reference = null)
16281629
}
16291630

16301631
if ($this->container->hasDefinition($id) && (!$this->container->getDefinition($id)->isPublic() || $this->container->getDefinition($id)->isShared())) {
1631-
// The following is PHP 5.5 syntax for what could be written as "(\$this->services['$id'] ?? $code)" on PHP>=7.0
1632-
1633-
$code = "\${(\$_ = isset(\$this->services['$id']) ? \$this->services['$id'] : $code) && false ?: '_'}";
1632+
$code = "(\$this->services['$id'] ?? $code)";
16341633
}
16351634

16361635
return $code;

src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ public static function getSignature(\ReflectionFunctionAbstract $r, &$call = nul
4949
$k = substr($k, 1);
5050
}
5151
} catch (\ReflectionException $e) {
52-
if ($type && $p->allowsNull() && !class_exists('ReflectionNamedType', false)) {
53-
$k .= ' = null';
54-
$k = substr($k, 1);
55-
}
5652
}
5753

5854
$signature[] = $k;

0 commit comments

Comments
 (0)