diff --git a/src/Analysers/TokenScanner.php b/src/Analysers/TokenScanner.php index 1df38be34..9c301f145 100644 --- a/src/Analysers/TokenScanner.php +++ b/src/Analysers/TokenScanner.php @@ -31,6 +31,7 @@ protected function scanTokens(array $tokens): array $units = []; $uses = []; $isInterface = false; + $isAbstractFunction = false; $namespace = ''; $currentName = null; $unitLevel = 0; @@ -65,6 +66,12 @@ protected function scanTokens(array $tokens): array } switch ($token[0]) { + case T_ABSTRACT: + if (count($stack)) { + $isAbstractFunction = true; + } + break; + case T_CURLY_OPEN: case T_DOLLAR_OPEN_CURLY_BRACES: $stack[] = $token[1]; @@ -151,7 +158,7 @@ protected function scanTokens(array $tokens): array if (($unitLevel + 1) == count($stack) && $currentName) { $units[$currentName]['methods'][] = $token[1]; - if (!$isInterface) { + if (!$isInterface && !$isAbstractFunction) { // more nesting $units[$currentName]['properties'] = array_merge( $units[$currentName]['properties'], @@ -161,6 +168,7 @@ protected function scanTokens(array $tokens): array } else { // no function body $this->skipTo($tokens, ';'); + $isAbstractFunction = false; } } break; diff --git a/tests/Analysers/TokenScannerTest.php b/tests/Analysers/TokenScannerTest.php index dadd31646..24e973200 100644 --- a/tests/Analysers/TokenScannerTest.php +++ b/tests/Analysers/TokenScannerTest.php @@ -13,6 +13,23 @@ class TokenScannerTest extends OpenApiTestCase { public function scanCases(): iterable { + if (\PHP_VERSION_ID >= 80100) { + yield 'abstract' => [ + 'PHP/AbstractKeyword.php', + [ + 'OpenApi\Tests\Fixtures\PHP\AbstractKeyword' => [ + 'uses' => [ + 'Property' => 'OpenApi\Attributes\Property', + ], + 'interfaces' => [], + 'traits' => [], + 'enums' => [], + 'methods' => ['stuff', 'other', 'another'], + 'properties' => [], + ], + ], + ]; + } if (\PHP_VERSION_ID >= 80100) { yield 'basic' => [ 'Apis/DocBlocks/basic.php', @@ -224,7 +241,9 @@ public function scanCases(): iterable 'PHP/Php8NamedArguments.php', [ 'OpenApi\\Tests\\Fixtures\\PHP\\Php8NamedArguments' => [ - 'uses' => [], + 'uses' => [ + 'OA' => 'OpenApi\Annotations', + ], 'interfaces' => [], 'traits' => [], 'enums' => [], @@ -238,7 +257,9 @@ public function scanCases(): iterable 'PHP/AnonymousFunctions.php', [ 'OpenApi\\Tests\\Fixtures\\PHP\\AnonymousFunctions' => [ - 'uses' => [], + 'uses' => [ + 'OA' => 'OpenApi\Annotations', + ], 'interfaces' => [], 'traits' => [], 'enums' => [], diff --git a/tests/Fixtures/PHP/AbstractKeyword.php b/tests/Fixtures/PHP/AbstractKeyword.php new file mode 100644 index 000000000..7cd1e980c --- /dev/null +++ b/tests/Fixtures/PHP/AbstractKeyword.php @@ -0,0 +1,25 @@ +shortFn(); + return $this->shortFn(); } public function dollarCurly2(string $key = 'xx') diff --git a/tests/Fixtures/PHP/Php8AttrMix.php b/tests/Fixtures/PHP/Php8AttrMix.php index 6a9c325df..0b155c77d 100644 --- a/tests/Fixtures/PHP/Php8AttrMix.php +++ b/tests/Fixtures/PHP/Php8AttrMix.php @@ -6,6 +6,8 @@ namespace OpenApi\Tests\Fixtures\PHP; +use OpenApi\Annotations as OA; + /** * @OA\Schema */ diff --git a/tests/Fixtures/PHP/Php8NamedArguments.php b/tests/Fixtures/PHP/Php8NamedArguments.php index 1d44b6336..6a02487a4 100644 --- a/tests/Fixtures/PHP/Php8NamedArguments.php +++ b/tests/Fixtures/PHP/Php8NamedArguments.php @@ -6,6 +6,8 @@ namespace OpenApi\Tests\Fixtures\PHP; +use OpenApi\Annotations as OA; + /** * @OA\Schema */