Skip to content

Commit

Permalink
fix issue #122
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville authored and icanhazstring committed Mar 8, 2024
1 parent 460096c commit bd88aec
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Parser/PHP/DefinedSymbolCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public function enterNode(Node $node)
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
}

if ($node instanceof Node\Stmt\Expression && $node->expr instanceof Node\Expr\FuncCall) {
if (
$node instanceof Node\Stmt\Expression &&
$node->expr instanceof Node\Expr\FuncCall &&
$node->expr->name instanceof Node\Name
) {
/** @var Node\Name $expressionName */
$expressionName = $node->expr->name;
$functionName = $expressionName->getParts()[0] ?? null;
Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/Parser/PHP/SymbolNameParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,28 @@ class Foo extends MyClass implements NameSpace1\Bar, \Other\Namespace2\Baz {
self::assertSame('My\NameSpace1\Bar', $symbols[2]);
self::assertSame('Other\Namespace2\Baz', $symbols[3]);
}

/**
* @test
* @link https://github.com/composer-unused/symbol-parser/issues/122
*/
public function itShouldParseDefinedClosureDirectCalls(): void
{
$code = <<<'CODE'
<?php
$handlers = [
function () { echo "Hello Handler\n"; },
];
foreach ($handlers as $handler) {
if (is_callable($handler)) {
$handler();
}
}
CODE;

$symbols = $this->parseDefinedSymbols($code);

self::assertCount(0, $symbols);
}
}

0 comments on commit bd88aec

Please sign in to comment.