Skip to content

Commit 445e063

Browse files
siskludg
authored andcommitted
Extractor: Fixed extracting enum method body [Closes #115] (#116)
1 parent ce44913 commit 445e063

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/PhpGenerator/Extractor.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public function extractMethodBodies(string $className): array
6666
$nodeFinder = new NodeFinder;
6767
$classNode = $nodeFinder->findFirst(
6868
$this->statements,
69-
fn(Node $node) => ($node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Trait_)
70-
&& $node->namespacedName->toString() === $className,
69+
fn(Node $node) => $node instanceof Node\Stmt\ClassLike && $node->namespacedName->toString() === $className,
7170
);
7271

7372
$res = [];

tests/PhpGenerator/Extractor.getMethodBodies.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ abstract class Another
3535
echo 123;
3636
}
3737
}
38+
39+
enum Color
40+
{
41+
case Red;
42+
case Blue;
43+
44+
public function getName(): string
45+
{
46+
return $this->name;
47+
}
48+
}
3849
');
3950

4051
$bodies = $extractor->extractMethodBodies('NS\Undefined');
@@ -45,3 +56,8 @@ Assert::same([
4556
'bar1' => "\$a = 10;\necho 123;",
4657
'bar2' => 'echo "hello";',
4758
], $bodies);
59+
60+
$bodies = $extractor->extractMethodBodies('NS\Color');
61+
Assert::same([
62+
'getName' => 'return $this->name;',
63+
], $bodies);

0 commit comments

Comments
 (0)