Skip to content

Commit

Permalink
Handle '&' used for return by reference (#1274)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann authored Jun 29, 2022
1 parent 7a316d9 commit 41c03aa
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Analysers/TokenScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ protected function scanTokens(array $tokens): array

case T_FUNCTION:
$token = $this->nextToken($tokens);
if ((!is_array($token) && '&' == $token)
|| (defined('T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG') && T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG == $token[0])) {
$token = $this->nextToken($tokens);
}

if (($unitLevel + 1) == count($stack) && $currentName) {
$units[$currentName]['methods'][] = $token[1];
Expand Down
18 changes: 18 additions & 0 deletions tests/Analysers/TokenScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ public function scanCases()
];
}

yield 'references' => [
'PHP/References.php',
[
'OpenApi\Tests\Fixtures\PHP\References' => [
'uses' => [
'OA' => 'OpenApi\Annotations',
],
'interfaces' => [],
'traits' => [],
'enums' => [],
'methods' => [
'return_ref',
],
'properties' => [],
],
],
];

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

/**
* @license Apache 2.0
*/

namespace OpenApi\Tests\Fixtures\PHP;

use OpenApi\Annotations as OA;

/**
* @OA\Schema
*/
class References
{
/**
* @OA\Property
*/
public function &return_ref()
{
$var = 1;

return $var;
}
}

0 comments on commit 41c03aa

Please sign in to comment.