diff --git a/src/PhpGenerator/Extractor.php b/src/PhpGenerator/Extractor.php index 50164ced..c3b0daa5 100644 --- a/src/PhpGenerator/Extractor.php +++ b/src/PhpGenerator/Extractor.php @@ -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 = []; diff --git a/tests/PhpGenerator/Extractor.getMethodBodies.phpt b/tests/PhpGenerator/Extractor.getMethodBodies.phpt index 1ebf3d6c..4cb6c14a 100644 --- a/tests/PhpGenerator/Extractor.getMethodBodies.phpt +++ b/tests/PhpGenerator/Extractor.getMethodBodies.phpt @@ -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'); @@ -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);