Skip to content

Commit

Permalink
Simplify implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 2, 2023
1 parent a7e9698 commit 7d568c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 1 addition & 11 deletions src/Parser/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,17 +521,7 @@ private function parseCallableReturnType(TokenIterator $tokens): Ast\Type\TypeNo
$startLine = $tokens->currentTokenLine();
$startIndex = $tokens->currentTokenIndex();
if ($tokens->isCurrentTokenType(Lexer::TOKEN_NULLABLE)) {
$type = $this->parseNullable($tokens);
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
$type = $this->tryParseArrayOrOffsetAccess($tokens, $this->enrichWithAttributes(
$tokens,
$type,
$startLine,
$startIndex
));
}

return $type;
return $this->parseNullable($tokens);

} elseif ($tokens->tryConsumeTokenType(Lexer::TOKEN_OPEN_PARENTHESES)) {
$type = $this->parse($tokens);
Expand Down
12 changes: 12 additions & 0 deletions tests/PHPStan/Parser/TypeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,18 @@ public function provideParseData(): array
'callable(): Foo::*',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new ConstTypeNode(new ConstFetchNode('Foo', '*'))),
],
[
'?Foo[]',
new NullableTypeNode(new ArrayTypeNode(new IdentifierTypeNode('Foo'))),
],
[
'callable(): ?Foo',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new NullableTypeNode(new IdentifierTypeNode('Foo'))),
],
[
'callable(): ?Foo[]',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new NullableTypeNode(new ArrayTypeNode(new IdentifierTypeNode('Foo')))),
],
];
}

Expand Down

0 comments on commit 7d568c8

Please sign in to comment.