Skip to content

Commit 2957e8b

Browse files
committed
[Debug][DebugClassLoader] Match callable() type for parameters not defined in sub classes
1 parent 14d458d commit 2957e8b

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public function checkAnnotations(\ReflectionClass $refl, $class)
375375
if ($finalOrInternal || $method->isConstructor() || false === \strpos($doc, '@param') || StatelessInvocation::class === $class) {
376376
continue;
377377
}
378-
if (!preg_match_all('#\n\s+\* @param (.*?)(?<= )\$([a-zA-Z0-9_\x7f-\xff]++)#', $doc, $matches, PREG_SET_ORDER)) {
378+
if (!preg_match_all('#\n\s+\* @param (callable(?:\(.*\))? *|.*?)\$([a-zA-Z0-9_\x7f-\xff]++)#', $doc, $matches, PREG_SET_ORDER)) {
379379
continue;
380380
}
381381
if (!isset(self::$annotatedParameters[$class][$method->name])) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ class_exists(__NAMESPACE__.'\\Fixtures\SubClassWithAnnotatedParameters', true);
287287
$this->assertSame([
288288
'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::quzMethod()" method will require a new "Quz $quz" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\ClassWithAnnotatedParameters", not defining it is deprecated.',
289289
'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::whereAmI()" method will require a new "bool $matrix" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.',
290+
'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "$noType" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.',
291+
'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "callable(\Throwable|null $reason, mixed $value) $callback" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.',
292+
'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "string $param" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.',
290293
'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::isSymfony()" method will require a new "true $yes" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\ClassWithAnnotatedParameters", not defining it is deprecated.',
291294
], $deprecations);
292295
}

src/Symfony/Component/Debug/Tests/Fixtures/InterfaceWithAnnotatedParameters.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,12 @@ interface InterfaceWithAnnotatedParameters
1111
* @param bool $matrix
1212
*/
1313
public function whereAmI();
14+
15+
/**
16+
* @param $noType
17+
* @param callable(\Throwable|null $reason, mixed $value) $callback and a comment
18+
* about this great param
19+
* @param string $param (comment with $dollar)
20+
*/
21+
public function iAmHere();
1422
}

src/Symfony/Component/Debug/Tests/Fixtures/SubClassWithAnnotatedParameters.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ public function quzMethod()
2121
public function whereAmI()
2222
{
2323
}
24+
25+
public function iAmHere()
26+
{
27+
}
2428
}

0 commit comments

Comments
 (0)