Skip to content

Commit

Permalink
Fix token parser skip closing curly brace (#1468)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fantom409 authored Aug 30, 2023
1 parent 6279683 commit e1062da
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Analysers/TokenScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function scanTokens(array $tokens): array
while (false !== ($token = $this->nextToken($tokens))) {
// named arguments
$nextToken = $this->nextToken($tokens);
if ($nextToken === ':' || $nextToken === false) {
if (($token !== '}' && $nextToken === ':') || $nextToken === false) {
continue;
}
do {
Expand Down
19 changes: 19 additions & 0 deletions tests/Analysers/TokenScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,25 @@ public function scanCases(): iterable
],
];

yield 'CurlyBrace' => [
'PHP/MultipleFunctions.php',
[
'OpenApi\Tests\Fixtures\PHP\MultipleFunctions' => [
'uses' => [
'OA' => 'OpenApi\Annotations',
],
'interfaces' => [],
'traits' => [],
'enums' => [],
'methods' => [
'first',
'second',
],
'properties' => [],
],
],
];

yield 'namespaces1' => [
'PHP/namespaces1.php',
[
Expand Down
31 changes: 31 additions & 0 deletions tests/Fixtures/PHP/MultipleFunctions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php declare(strict_types=1);

/**
* @license Apache 2.0
*/

namespace OpenApi\Tests\Fixtures\PHP;

use OpenApi\Annotations as OA;

/**
* @OA\Info(title="Test", version="1.0")
*/
class MultipleFunctions
{
public function first()
{
$category = new \stdClass();
$prefix = '1';
$category->name = '1';

return isset($category->{'name' . $prefix}) && $category->{'name' . $prefix}
? $category->{'name' . $prefix}
: $category->name;
}

public function second()
{

}
}

0 comments on commit e1062da

Please sign in to comment.