Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/Commands/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions tests/Commands/GenerateInterfaceUnionsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions workbench/app/Models/AttributeClassAndEnumReferenceAnimal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Models;

use App\Attributes\ModelInfo;
use App\Enums\AnimalType;
use App\Interfaces\AnimalInterface;

#[ModelInfo(ParentAnimal::class, AnimalType::Dog)]
class AttributeClassAndEnumReferenceAnimal implements AnimalInterface
{
}
Loading