Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e352d06

Browse files
jiripudilondrejmirtes
authored andcommitted
type aliases: detect unsupported targets of type alias imports on parsing level
1 parent e24edb6 commit e352d06

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

‎src/Parser/PhpDocParser.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,16 +403,16 @@ private function parseTypeAliasImportTagValue(TokenIterator $tokens): Ast\PhpDoc
403403
);
404404
}
405405

406-
$importedFrom = $this->typeParser->parse($tokens);
407-
assert($importedFrominstanceof IdentifierTypeNode);
406+
$importedFrom = $tokens->currentTokenValue();
407+
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);
408408

409409
$importedAs = null;
410410
if ($tokens->tryConsumeTokenValue('as')) {
411411
$importedAs = $tokens->currentTokenValue();
412412
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);
413413
}
414414

415-
return new Ast\PhpDoc\TypeAliasImportTagValueNode($importedAlias, $importedFrom, $importedAs);
415+
return new Ast\PhpDoc\TypeAliasImportTagValueNode($importedAlias, newIdentifierTypeNode($importedFrom), $importedAs);
416416
}
417417

418418
private function parseOptionalVariableName(TokenIterator $tokens): string

‎tests/PHPStan/Parser/PhpDocParserTest.php‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,6 +2988,44 @@ public function provideTypeAliasImportTagsData(): \Iterator
29882988
]),
29892989
];
29902990

2991+
yield [
2992+
'invalid non-identifier from',
2993+
'/** @phpstan-import-type TypeAlias from 42 */',
2994+
new PhpDocNode([
2995+
new PhpDocTagNode(
2996+
'@phpstan-import-type',
2997+
new InvalidTagValueNode(
2998+
'TypeAlias from 42',
2999+
new \PHPStan\PhpDocParser\Parser\ParserException(
3000+
'42',
3001+
Lexer::TOKEN_INTEGER,
3002+
40,
3003+
Lexer::TOKEN_IDENTIFIER
3004+
)
3005+
)
3006+
),
3007+
]),
3008+
];
3009+
3010+
yield [
3011+
'invalid non-simple-identifier from',
3012+
'/** @phpstan-import-type TypeAlias from AnotherClass[] */',
3013+
new PhpDocNode([
3014+
new PhpDocTagNode(
3015+
'@phpstan-import-type',
3016+
new InvalidTagValueNode(
3017+
'Unexpected token "[", expected \'*/\' at offset 52',
3018+
new \PHPStan\PhpDocParser\Parser\ParserException(
3019+
'[',
3020+
Lexer::TOKEN_OPEN_SQUARE_BRACKET,
3021+
52,
3022+
Lexer::TOKEN_CLOSE_PHPDOC
3023+
)
3024+
)
3025+
),
3026+
]),
3027+
];
3028+
29913029
yield [
29923030
'invalid missing from',
29933031
'/** @phpstan-import-type TypeAlias */',

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /