Skip to content

Commit

Permalink
Fix parsing magic method annotations
Browse files Browse the repository at this point in the history
Fix parsing for code:

```
/**
 * @method static (string|int)[] getArray()
 * @method static (callable() : string) getCallable()
 */
class MyClass {}
```

Resolved tests:

```
1) testMethodAnnotation with data set "static (string|int)[] getArray()"
2) testMethodAnnotation with data set "static (callable() : string) getCallable()"
```
  • Loading branch information
issidorov committed Feb 6, 2024
1 parent 6b3380b commit afaaa3d
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,19 @@ public static function parse(

$has_return = false;

if (!preg_match('/^([a-z_A-Z][a-z_0-9A-Z]+) *\(/', $method_entry, $matches)) {
$doc_line_parts = CommentAnalyzer::splitDocLine($method_entry);
$doc_line_parts = CommentAnalyzer::splitDocLine($method_entry);

if ($doc_line_parts[0] === 'static' && !strpos($doc_line_parts[1], '(')) {
$is_static = true;
array_shift($doc_line_parts);
}
if (count($doc_line_parts) > 2
&& $doc_line_parts[0] === 'static'
&& !strpos($doc_line_parts[1], '(')
) {
$is_static = true;
array_shift($doc_line_parts);
$method_entry = implode(' ', $doc_line_parts);
$doc_line_parts = CommentAnalyzer::splitDocLine($method_entry);
}

if (!preg_match('/^([a-z_A-Z][a-z_0-9A-Z]+) *\(/', $method_entry, $matches)) {
if (count($doc_line_parts) > 1) {
$docblock_lines[] = '@return ' . array_shift($doc_line_parts);
$has_return = true;
Expand Down

0 comments on commit afaaa3d

Please sign in to comment.