From 372e96e157e282e84dada0430c02dc5a76c2d9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 18 May 2017 09:09:34 +0200 Subject: [PATCH] [DependencyInjection] Remove dead code with PHP 7+ --- .../DependencyInjection/Compiler/AutowirePass.php | 5 ++--- .../Compiler/FactoryReturnTypePass.php | 4 ---- .../DependencyInjection/LazyProxy/ProxyHelper.php | 14 +++----------- .../Tests/Compiler/FactoryReturnTypePassTest.php | 15 +++------------ 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index 0a6a0dfc1b..07ecdcb340 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -250,7 +250,7 @@ class AutowirePass extends AbstractRecursivePass $class = $reflectionMethod instanceof \ReflectionMethod ? $reflectionMethod->class : $this->currentId; $method = $reflectionMethod->name; $parameters = $reflectionMethod->getParameters(); - if (method_exists('ReflectionMethod', 'isVariadic') && $reflectionMethod->isVariadic()) { + if ($reflectionMethod->isVariadic()) { array_pop($parameters); } @@ -533,11 +533,10 @@ class AutowirePass extends AbstractRecursivePass $class = false; } - $isVariadic = method_exists($parameter, 'isVariadic') && $parameter->isVariadic(); $methodArgumentsMetadata[] = array( 'class' => $class, 'isOptional' => $parameter->isOptional(), - 'defaultValue' => ($parameter->isOptional() && !$isVariadic) ? $parameter->getDefaultValue() : null, + 'defaultValue' => ($parameter->isOptional() && !$parameter->isVariadic()) ? $parameter->getDefaultValue() : null, ); } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/FactoryReturnTypePass.php b/src/Symfony/Component/DependencyInjection/Compiler/FactoryReturnTypePass.php index 3ba4a8caa0..84f9c6bc16 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/FactoryReturnTypePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/FactoryReturnTypePass.php @@ -37,10 +37,6 @@ class FactoryReturnTypePass implements CompilerPassInterface */ public function process(ContainerBuilder $container) { - // works only since php 7.0 and hhvm 3.11 - if (!method_exists(\ReflectionMethod::class, 'getReturnType')) { - return; - } $resolveClassPassChanges = null !== $this->resolveClassPass ? $this->resolveClassPass->getChanges() : array(); foreach ($container->getDefinitions() as $id => $definition) { diff --git a/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php b/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php index 5f0c8772fe..b6115ea7dc 100644 --- a/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php +++ b/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php @@ -28,7 +28,7 @@ class ProxyHelper foreach ($r->getParameters() as $i => $p) { $k = '$'.$p->name; - if (method_exists($p, 'isVariadic') && $p->isVariadic()) { + if ($p->isVariadic()) { $k = '...'.$k; } $call[] = $k; @@ -72,17 +72,9 @@ class ProxyHelper public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionParameter $p = null, $noBuiltin = false) { if ($p instanceof \ReflectionParameter) { - if (method_exists($p, 'getType')) { - $type = $p->getType(); - } elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $p, $type)) { - $name = $type = $type[1]; - - if ('callable' === $name || 'array' === $name) { - return $noBuiltin ? null : $name; - } - } + $type = $p->getType(); } else { - $type = method_exists($r, 'getReturnType') ? $r->getReturnType() : null; + $type = $r->getReturnType(); } if (!$type) { return; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php index f299463d5f..5d5f5339be 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php @@ -44,13 +44,8 @@ class FactoryReturnTypePassTest extends TestCase $pass = new FactoryReturnTypePass(); $pass->process($container); - if (method_exists(\ReflectionMethod::class, 'getReturnType')) { - $this->assertEquals(FactoryDummy::class, $factory->getClass()); - $this->assertEquals(\stdClass::class, $foo->getClass()); - } else { - $this->assertNull($factory->getClass()); - $this->assertNull($foo->getClass()); - } + $this->assertEquals(FactoryDummy::class, $factory->getClass()); + $this->assertEquals(\stdClass::class, $foo->getClass()); $this->assertEquals(__CLASS__, $bar->getClass()); } @@ -71,11 +66,7 @@ class FactoryReturnTypePassTest extends TestCase $pass = new FactoryReturnTypePass(); $pass->process($container); - if (method_exists(\ReflectionMethod::class, 'getReturnType')) { - $this->assertEquals($returnType, $service->getClass()); - } else { - $this->assertNull($service->getClass()); - } + $this->assertEquals($returnType, $service->getClass()); } public function returnTypesProvider()