8000 Update root-composer (major) by renovate[bot] · Pull Request #176 · phpstan/phpdoc-parser · GitHub
[go: up one dir, main page]

Skip to content

Update root-composer (major) #176

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

Open
wants to merge 15 commits into
base: 1.9.x
Choose a base branch
from
Open
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
Prev Previous commit
Next Next commit
CallableTypeNode - support object shape in return type
  • Loading branch information
ondrejmirtes committed May 2, 2023
commit d60fa73f5c3215d122391a13f9c89dce86f34a82
18 changes: 11 additions & 7 deletions src/Parser/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,17 @@ private function parseCallableReturnType(TokenIterator $tokens): Ast\Type\TypeNo
)
);

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

Expand Down
18 changes: 18 additions & 0 deletions tests/PHPStan/Parser/TypeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,24 @@ public function provideParseData(): array
'callable(): ?int',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new NullableTypeNode(new IdentifierTypeNode('int'))),
],
[
'callable(): object{foo: int}',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new ObjectShapeNode([
new ObjectShapeItemNode(new IdentifierTypeNode('foo'), false, new IdentifierTypeNode('int')),
])),
],
[
'callable(): object{foo: int}[]',
new CallableTypeNode(
new IdentifierTypeNode('callable'),
[],
new ArrayTypeNode(
new ObjectShapeNode([
new ObjectShapeItemNode(new IdentifierTypeNode('foo'), false, new IdentifierTypeNode('int')),
])
)
),
],
];
}

Expand Down
0