Skip to content

Commit

Permalink
Ast: NamedType - added support for 'static' keyword (PHP 8.0+)
Browse files Browse the repository at this point in the history
  • Loading branch information
janpecha committed Mar 19, 2024
1 parent d4ffa4e commit b605fb5
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Ast/NamedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public static function parse(NodeParser $parser)
} elseif ($parser->isCurrent(T_CALLABLE)) {
$type = $parser->consumeTokenAsText(T_CALLABLE);

} elseif ($parser->isCurrent(T_STATIC)) {
$type = $parser->consumeTokenAsText(T_STATIC);

} else {
$name = Name::parse($parser->createSubParser());
$type = $name->toString();
Expand Down
66 changes: 66 additions & 0 deletions tests/PhpSimpleAst/fixtures/PHP-8.0/80000.static-return-type.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
CzProject\PhpSimpleAst\Ast\PhpString
children: array (1)
| 0 => CzProject\PhpSimpleAst\Ast\PhpNode
| | openTag: '<?php\n'
| | children: array (2)
| | | 0 => CzProject\PhpSimpleAst\Ast\ClassNode
| | | | indentation: '\n'
| | | | keyword: 'class'
| | | | name: CzProject\PhpSimpleAst\Ast\Name
| | | | | indentation: ' '
| | | | | name: 'Foo'
| | | | constructorValues: null
| | | | extends: null
| | | | implements: null
| | | | blockOpener: ' {'
| | | | children: array (1)
| | | | | 0 => CzProject\PhpSimpleAst\Ast\MethodNode
| | | | | | phpDocNode: null
| | | | | | indentation: string
| | | | | | | '\n
| | | | | | | \t '
| | | | | | modifiers: array (2)
| | | | | | | 0 => CzProject\PhpSimpleAst\Ast\Visibility
| | | | | | | | indentation: ''
| | | | | | | | visibility: 'public'
| | | | | | | 1 => CzProject\PhpSimpleAst\Ast\StaticModifier
| | | | | | | | indentation: ' '
| | | | | | | | modifier: 'static'
| | | | | | keywordPrefix: ' '
| | | | | | keyword: 'function'
| | | | | | name: CzProject\PhpSimpleAst\Ast\Name
| | | | | | | indentation: ' '
| | | | | | | name: 'getInstance'
| | | | | | parameters: CzProject\PhpSimpleAst\Ast\Parameters
| | | | | | | indentation: ''
| | | | | | | opener: '('
| | | | | | | parameters: array (0)
| | | | | | | closer: ')'
| | | | | | returnType: CzProject\PhpSimpleAst\Ast\FunctionReturnType
| | | | | | | indentation: ': '
| | | | | | | nullable: false
| | | | | | | type: CzProject\PhpSimpleAst\Ast\Type
| | | | | | | | indentation: ''
| | | | | | | | types: array (1)
| | | | | | | | | 0 => CzProject\PhpSimpleAst\Ast\NamedType
| | | | | | | | | | indentation: ''
| | | | | | | | | | nullableSign: ''
| | | | | | | | | | typeIndentation: ''
| | | | | | | | | | type: 'static'
| | | | | | body: CzProject\PhpSimpleAst\Ast\FunctionBody
| | | | | | | indentation: ' '
| | | | | | | blockOpener: '{'
| | | | | | | children: array (1)
| | | | | | | | 0 => CzProject\PhpSimpleAst\Ast\UnknowNode
| | | | | | | | | content: string
| | | | | | | | | | '\n
| | | | | | | | | | \t \t return new static();'
| | | | | | | blockCloser: string
| | | | | | | | '\n
| | | | | | | | \t }'
| | | | blockCloser: string
| | | | | '\n
| | | | | }'
| | | 1 => CzProject\PhpSimpleAst\Ast\UnknowNode
| | | | content: '\n'
| | closeTag: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class Foo {
public static function getInstance(): static {
return new static();
}
}

0 comments on commit b605fb5

Please sign in to comment.