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

Add support for list shapes #175

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

Merged
ondrejmirtes merged 2 commits into phpstan:1.9.x from zonuexe:feature/list-shapes
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions src/Parser/TypeParser.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use LogicException;
use PHPStan\PhpDocParser\Ast;
use PHPStan\PhpDocParser\Lexer\Lexer;
use function in_array;
use function strpos;
use function trim;

Expand Down Expand Up @@ -123,7 +124,7 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
} elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
$type = $this->tryParseArrayOrOffsetAccess($tokens, $type);

} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
} elseif (in_array($type->name, ['array', 'list'], true) && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
$type = $this->parseArrayShape($tokens, $type);

if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
Expand Down Expand Up @@ -439,7 +440,7 @@ private function parseCallableReturnType(TokenIterator $tokens): Ast\Type\TypeNo
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)) {
$type = $this->parseGeneric($tokens, $type);

} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
} elseif (in_array($type->name, ['array', 'list'], true) && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
$type = $this->parseArrayShape($tokens, $type);
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/PHPStan/Parser/TypeParserTest.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,24 @@ public function provideParseData(): array
Lexer::TOKEN_CLOSE_CURLY_BRACKET
),
],
[
'list{
int,
string
}',
new ArrayShapeNode([
Copy link
Member

@ondrejmirtes ondrejmirtes Jan 29, 2023

Choose a reason for hiding this comment

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

Would be nice to know the array shape "kind" (array or list) at the ArrayShapeNode class.

zonuexe reacted with thumbs up emoji
new ArrayShapeItemNode(
null,
false,
new IdentifierTypeNode('int')
),
new ArrayShapeItemNode(
null,
false,
new IdentifierTypeNode('string')
),
]),
],
[
'callable(): Foo',
new CallableTypeNode(
Expand Down

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