10000 [DependencyInjection] Remove dead code with PHP 7+ · symfony/symfony@372e96e · GitHub
[go: up one dir, main page]

Skip to content

Commit 372e96e

Browse files
committed
[DependencyInjection] Remove dead code with PHP 7+
1 parent 15b7cdb commit 372e96e

File tree

4 files changed

+8
-30
lines changed

4 files changed

+8
-30
lines changed

src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
250250
$class = $reflectionMethod instanceof \ReflectionMethod ? $reflectionMethod->class : $this->currentId;
251251
$method = $reflectionMethod->name;
252252
$parameters = $reflectionMethod->getParameters();
253-
if (method_exists('ReflectionMethod', 'isVariadic') && $reflectionMethod->isVariadic()) {
253+
if ($reflectionMethod->isVariadic()) {
254254
array_pop($parameters);
255255
}
256256

@@ -533,11 +533,10 @@ private static function getResourceMetadataForMethod(\ReflectionMethod $method)
533533
$class = false;
534534
}
535535

536-
$isVariadic = method_exists($parameter, 'isVariadic') && $parameter->isVariadic();
537536
$methodArgumentsMetadata[] = array(
538537
'class' => $class,
539538
'isOptional' => $parameter->isOptional(),
540-
'defaultValue' => ($parameter->isOptional() && !$isVariadic) ? $parameter->getDefaultValue() : null,
539+
'defaultValue' => ($parameter->isOptional() && !$parameter->isVariadic()) ? $parameter->getDefaultValue() : null,
541540
);
542541
}
543542

src/Symfony/Component/DependencyInjection/Compiler/FactoryReturnTypePass.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ public function __construct(ResolveClassPass $resolveClassPass = null)
3737
*/
3838
public function process(ContainerBuilder $container)
3939
{
40-
// works only since php 7.0 and hhvm 3.11
41-
if (!method_exists(\ReflectionMethod::class, 'getReturnType')) {
42-
return;
43-
}
4440
$resolveClassPassChanges = null !== $this->resolveClassPass ? $this->resolveClassPass->getChanges() : array();
4541

4642
foreach ($container->getDefinitions() as $id => $definition) {

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static function getSignature(\ReflectionFunctionAbstract $r, &$call = nul
2828

2929
foreach ($r->getParameters() as $i => $p) {
3030
$k = '$'.$p->name;
31-
if (method_exists($p, 'isVariadic') && $p->isVariadic()) {
31+
if ($p->isVariadic()) {
3232
$k = '...'.$k;
3333
}
3434
$call[] = $k;
@@ -72,17 +72,9 @@ public static function getSignature(\ReflectionFunctionAbstract $r, &$call = nul
7272
public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionParameter $p = null, $noBuiltin = false)
7373
{
7474
if ($p instanceof \ReflectionParameter) {
75-
if (method_exists($p, 'getType')) {
76-
$type = $p->getType();
77-
} elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $p, $type)) {
78-
$name = $type = $type[1];
79-
80-
if ('callable' === $name || 'array' === $name) {
81-
return $noBuiltin ? null : $name;
82-
}
83-
}
75+
$type = $p->getType();
8476
} else {
85-
$type = method_exists($r, 'getReturnType') ? $r->getReturnType() : null;
77+
$type = $r->getReturnType();
8678
}
8779
if (!$type) {
8880
return;

src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,8 @@ public function testProcess()
4444
$pass = new FactoryReturnTypePass();
4545
$pass->process($container);
4646

47-
if (method_exists(\ReflectionMethod::class, 'getReturnType')) {
48-
$this->assertEquals(FactoryDummy::class, $factory->getClass());
49-
$this->assertEquals(\stdClass::class, $foo->getClass());
50-
} else {
51-
$this->assertNull($factory->getClass());
52-
$this->assertNull($foo->getClass());
53-
}
47+
$this->assertEquals(FactoryDummy::class, $factory->getClass());
48+
$this->assertEquals(\stdClass::class, $foo->getClass());
5449
$this->assertEquals(__CLASS__, $bar->getClass());
5550
}
5651

@@ -71,11 +66,7 @@ public function testReturnTypes($factory, $returnType, $hhvmSupport = true)
7166
$pass = new FactoryReturnTypePass();
7267
$pass->process($container);
7368

74-
if (method_exists(\ReflectionMethod::class, 'getReturnType')) {
75-
$this->assertEquals($returnType, $service->getClass());
76-
} else {
77-
$this->assertNull($service->getClass());
78-
}
69+
$this->assertEquals($returnType, $service->getClass());
7970
}
8071

8172
public function returnTypesProvider()

0 commit comments

Comments
 (0)
0