Skip to content

Commit 3659e32

Browse files
committed
minor #29988 [Debug][DebugClassLoader] Match callable() type for parameters not defined in sub classes (fancyweb)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Debug][DebugClassLoader] Match callable() type for parameters not defined in sub classes | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #29969 | License | MIT | Doc PR | - Added test fixture for multi param, no param type and multi spaces as well. BTW, I didn't understand why there was a positive lookbehind on the current regex. Looks useless to me and tests passes without it. Commits ------- 89c89c9 [Debug][DebugClassLoader] Match callable() type for parameters not defined in sub classes
2 parents 1aa652e + 89c89c9 commit 3659e32

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public function checkAnnotations(\ReflectionClass $refl, $class)
352352
}
353353

354354
foreach (self::$annotatedParameters[$class][$method->name] as $parameterName => $deprecation) {
355-
if (!isset($definedParameters[$parameterName]) && !($doc && preg_match("/\\n\\s+\\* @param (.*?)(?<= )\\\${$parameterName}\\b/", $doc))) {
355+
if (!isset($definedParameters[$parameterName]) && !($doc && preg_match("/\\n\\s+\\* @param +((?(?!callable *\().*?|callable *\(.*\).*?))(?<= )\\\${$parameterName}\\b/", $doc))) {
356356
$deprecations[] = sprintf($deprecation, $class);
357357
}
358358
}
@@ -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 *\().*?|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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ class_exists(__NAMESPACE__.'\\Fixtures\SubClassWithAnnotatedParameters', true);
294294
$this->assertSame([
295295
'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.',
296296
'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.',
297+
'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.',
298+
'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.',
299+
'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.',
300+
'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "callable ($a, $b) $anotherOne" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.',
301+
'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "Type$WithDollarIsStillAType $ccc" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.',
297302
'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.',
298303
], $deprecations);
299304
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,17 @@ 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+
* @param $defined
21+
* @param callable ($a, $b) $anotherOne
22+
* @param callable (mixed $a, $b) $definedCallable
23+
* @param Type$WithDollarIsStillAType $ccc
24+
* @param \JustAType
25+
*/
26+
public function iAmHere();
1427
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@ public function quzMethod()
2121
public function whereAmI()
2222
{
2323
}
24+
25+
/**
26+
* @param $defined
27+
* @param Type\Does\Not\Matter $definedCallable
28+
*/
29+
public function iAmHere()
30+
{
31+
}
2432
}

0 commit comments

Comments
 (0)