Skip to content

Commit 9e034d7

Browse files
authored
Merge pull request #463 from greg0ire/dont-cast-null
Do not cast null to array
2 parents 3587ab5 + fd04499 commit 9e034d7

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

lib/Doctrine/Common/Annotations/DocLexer.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,14 @@ protected function getType(&$value)
130130
}
131131

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

137+
if ($token === null) {
138+
return null;
139+
}
140+
137141
return (array) $token;
138142
}
139143
}

phpstan.neon

-2
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,3 @@ parameters:
2222

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

tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,9 @@ public function testTokenAdjacency(): void
320320
self::assertFalse($lexer->nextTokenIsAdjacent());
321321
self::assertFalse($lexer->moveNext());
322322
}
323+
324+
public function testItReturnsNullWhenThereIsNothingToParse(): void
325+
{
326+
self::assertNull((new DocLexer())->peek());
327+
}
323328
}

0 commit comments

Comments
 (0)