Skip to content

Commit 9b28925

Browse files
minor #53322 Leverage ReflectionFunction::isAnonymous() (nicolas-grekas)
This PR was merged into the 7.1 branch. Discussion ---------- Leverage ReflectionFunction::isAnonymous() | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Introduced in PHP 8.2 Commits ------- 1d26010b48 Leverage ReflectionFunction::isAnonymous()
2 parents 71d348a + dbd3ceb commit 9b28925

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

Console/Descriptor/JsonDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ private function getCallableData(mixed $callable): array
393393
$data['type'] = 'closure';
394394

395395
$r = new \ReflectionFunction($callable);
396-
if (str_contains($r->name, '{closure}')) {
396+
if ($r->isAnonymous()) {
397397
return $data;
398398
}
399399
$data['name'] = $r->name;

Console/Descriptor/MarkdownDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ protected function describeCallable(mixed $callable, array $options = []): void
403403
$string .= "\n- Type: `closure`";
404404

405405
$r = new \ReflectionFunction($callable);
406-
if (str_contains($r->name, '{closure}')) {
406+
if ($r->isAnonymous()) {
407407
$this->write($string."\n");
408408

409409
return;

Console/Descriptor/TextDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ private function formatCallable(mixed $callable): string
649649

650650
if ($callable instanceof \Closure) {
651651
$r = new \ReflectionFunction($callable);
652-
if (str_contains($r->name, '{closure}')) {
652+
if ($r->isAnonymous()) {
653653
return 'Closure()';
654654
}
655655
if ($class = $r->getClosureCalledClass()) {

Console/Descriptor/XmlDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ private function getCallableDocument(mixed $callable): \DOMDocument
581581
$callableXML->setAttribute('type', 'closure');
582582

583583
$r = new \ReflectionFunction($callable);
584-
if (str_contains($r->name, '{closure}')) {
584+
if ($r->isAnonymous()) {
585585
return $dom;
586586
}
587587
$callableXML->setAttribute('name', $r->name);

Kernel/MicroKernelTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function loadRoutes(LoaderInterface $loader): RouteCollection
214214

215215
if (\is_array($controller) && [0, 1] === array_keys($controller) && $this === $controller[0]) {
216216
$route->setDefault('_controller', ['kernel', $controller[1]]);
217-
} elseif ($controller instanceof \Closure && $this === ($r = new \ReflectionFunction($controller))->getClosureThis() && !str_contains($r->name, '{closure}')) {
217+
} elseif ($controller instanceof \Closure && $this === ($r = new \ReflectionFunction($controller))->getClosureThis() && !$r->isAnonymous()) {
218218
$route->setDefault('_controller', ['kernel', $r->name]);
219219
}
220220
}

0 commit comments

Comments
 (0)