Skip to content

Commit 2a56b03

Browse files
author
Kirill Nesmeyanov
committed
Parser should return non-nullable TypeStatement or throw an exception instead
1 parent 1a965fe commit 2a56b03

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/Parser.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private function createLexer(array $grammar): Lexer
120120
/**
121121
* @psalm-suppress UndefinedAttributeClass : Optional (builtin) attribute usage
122122
*/
123-
public function parse(#[Language('PHP')] mixed $source): ?TypeStatement
123+
public function parse(#[Language('PHP')] mixed $source): TypeStatement
124124
{
125125
$this->lastProcessedTokenOffset = 0;
126126

@@ -142,7 +142,10 @@ public function parse(#[Language('PHP')] mixed $source): ?TypeStatement
142142
}
143143
}
144144

145-
return null;
145+
throw new ParseException(
146+
message: 'Could not read type statement',
147+
code: ParseException::ERROR_CODE_INTERNAL_ERROR,
148+
);
146149
} catch (UnexpectedTokenException $e) {
147150
throw $this->unexpectedTokenError($e, $instance);
148151
} catch (UnrecognizedTokenException $e) {
@@ -161,8 +164,6 @@ public function parse(#[Language('PHP')] mixed $source): ?TypeStatement
161164
previous: $e,
162165
);
163166
}
164-
165-
return null;
166167
}
167168

168169
/**

src/ParserInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ interface ParserInterface
2121
*
2222
* @psalm-suppress UndefinedAttributeClass : Optional (builtin) attribute usage
2323
*/
24-
public function parse(#[Language('PHP')] mixed $source): ?TypeStatement;
24+
public function parse(#[Language('PHP')] mixed $source): TypeStatement;
2525
}

0 commit comments

Comments
 (0)