Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/PhpGenerator/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public function extractMethodBodies(string $className): array
$nodeFinder = new NodeFinder;
$classNode = $nodeFinder->findFirst(
$this->statements,
fn(Node $node) => ($node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Trait_)
&& $node->namespacedName->toString() === $className,
fn(Node $node) => $node instanceof Node\Stmt\ClassLike && $node->namespacedName->toString() === $className,
);

$res = [];
Expand Down
16 changes: 16 additions & 0 deletions tests/PhpGenerator/Extractor.getMethodBodies.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ abstract class Another
echo 123;
}
}

enum Color
{
case Red;
case Blue;

public function getName(): string
{
return $this->name;
}
}
');

$bodies = $extractor->extractMethodBodies('NS\Undefined');
Expand All @@ -45,3 +56,8 @@ Assert::same([
'bar1' => "\$a = 10;\necho 123;",
'bar2' => 'echo "hello";',
], $bodies);

$bodies = $extractor->extractMethodBodies('NS\Color');
Assert::same([
'getName' => "return \$this->name;",
], $bodies);