diff --git a/src/Commands/BaseCommand.php b/src/Commands/BaseCommand.php index 0423511..2eaa239 100644 --- a/src/Commands/BaseCommand.php +++ b/src/Commands/BaseCommand.php @@ -182,16 +182,14 @@ protected function findClassTokenIndex(array $tokens): ?int for ($lookahead = $index + 1; isset($tokens[$lookahead]); $lookahead++) { $nextToken = $tokens[$lookahead]; - if (!is_array($nextToken)) { - continue; - } - - if (in_array($nextToken[0], [T_WHITESPACE, T_COMMENT, T_DOC_COMMENT], true)) { - continue; - } + if (is_array($nextToken)) { + if (in_array($nextToken[0], [T_WHITESPACE, T_COMMENT, T_DOC_COMMENT], true)) { + continue; + } - if ($nextToken[0] === T_STRING) { - return $index; + if ($nextToken[0] === T_STRING) { + return $index; + } } break; diff --git a/tests/Commands/GenerateInterfaceUnionsCommandTest.php b/tests/Commands/GenerateInterfaceUnionsCommandTest.php index 9bf3ee2..4d634ce 100644 --- a/tests/Commands/GenerateInterfaceUnionsCommandTest.php +++ b/tests/Commands/GenerateInterfaceUnionsCommandTest.php @@ -121,6 +121,17 @@ public function testParserIgnoresClassConstantReferencesBeforeClassDeclaration() $this->assertSame(['App\\Interfaces\\AnimalInterface'], $info['implements']); } + public function testParserIgnoresClassConstantReferencesBeforeClassDeclarationWhenFollowedByEnumCase(): void + { + $info = $this->makeParserCommand()->classInfo( + './workbench/app/Models/AttributeClassAndEnumReferenceAnimal.php' + ); + + $this->assertSame('AttributeClassAndEnumReferenceAnimal', $info['class']); + $this->assertSame('App\\Models\\AttributeClassAndEnumReferenceAnimal', $info['fqcn']); + $this->assertSame(['App\\Interfaces\\AnimalInterface'], $info['implements']); + } + public function testCommandFailsForInvalidInputPath(): void { $this->expectException(\RuntimeException::class); diff --git a/workbench/app/Models/AttributeClassAndEnumReferenceAnimal.php b/workbench/app/Models/AttributeClassAndEnumReferenceAnimal.php new file mode 100644 index 0000000..8e2eb4b --- /dev/null +++ b/workbench/app/Models/AttributeClassAndEnumReferenceAnimal.php @@ -0,0 +1,12 @@ +