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 committed Sep 19, 2022
1 parent ce44913 commit 7e1f0c2
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
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
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 7e1f0c2

Please sign in to comment.