Skip to content

Commit

Permalink
Extractor: Fixed extracting enum method body [Closes #115] (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
sisklu authored and dg committed Oct 4, 2022
1 parent 9073c8a commit 6509699
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/PhpGenerator/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public function extractMethodBodies(string $className): array
{
$nodeFinder = new NodeFinder;
$classNode = $nodeFinder->findFirst($this->statements, function (Node $node) use ($className) {
return ($node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Trait_)
&& $node->namespacedName->toString() === $className;
return $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);

0 comments on commit 6509699

Please sign in to comment.