Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not cast null to array #463

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Doctrine/Common/Annotations/DocLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,14 @@ protected function getType(&$value)
}

/** @return array{value: int|string, type:self::T_*|null, position:int} */
public function peek(): array
public function peek(): ?array
{
$token = parent::peek();

if ($token === null) {
return null;
}

return (array) $token;
}
}
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ parameters:

# That tag is empty on purpose
- '#PHPDoc tag @var has invalid value \(\)\: Unexpected token "\*/", expected type at offset 9#'
# Backwards-compatibility
- '#^Return type.*of method.*DocLexer::peek.*should be compatible.*$#'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phpstan warned me 🙈

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the parent type returns array, so it should not be happy with this 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah Phpstan is only at level 3 🤔

5 changes: 5 additions & 0 deletions tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,9 @@ public function testTokenAdjacency(): void
self::assertFalse($lexer->nextTokenIsAdjacent());
self::assertFalse($lexer->moveNext());
}

public function testItReturnsNullWhenThereIsNothingToParse(): void
{
self::assertNull((new DocLexer())->peek());
}
}