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

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
renovate wants to merge 15 commits into 1.9.x
base: 1.9.x
Choose a base branch
Loading
from renovate/major-root-composer
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
2a022b2
Un-extract variable
ondrejmirtes Apr 28, 2023
68d46b9
Extract creating PhpDocParser to setUp
ondrejmirtes Apr 28, 2023
f5a5145
Test Printer::print()
ondrejmirtes Apr 28, 2023
2ebed2c
Open 1.20.x
ondrejmirtes May 2, 2023
16b30bb
Merge branch '1.20.x' into 1.21.x
ondrejmirtes May 2, 2023
e9514dc
Open 1.21.x
ondrejmirtes May 2, 2023
69bc46f
Update dependency slevomat/coding-standard to v8.11.1
renovate[bot] May 1, 2023
97d18ea
Fix build
ondrejmirtes May 2, 2023
d60fa73
CallableTypeNode - support object shape in return type
ondrejmirtes May 2, 2023
421d3f3
CallableTypeNode - support `$this` in return type
ondrejmirtes May 2, 2023
a7e9698
CallableTypeNode - support ConstTypeNode in return type
ondrejmirtes May 2, 2023
7d568c8
Simplify implementation
ondrejmirtes May 2, 2023
cc94635
Merge branch '1.20.x' into 1.21.x
ondrejmirtes May 2, 2023
ced520a
Micro optimize parseParamTagValue()
staabm May 16, 2023
bfdb616
Update root-composer
renovate[bot] May 17, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/backward-compatibility.yml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:
push:
branches:
- "1.9.x"
- "1.21.x"

jobs:
backward-compatibility:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:
push:
branches:
- "1.9.x"
- "1.21.x"

jobs:
lint:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-slevomat-coding-standard.yml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:
push:
branches:
- "1.9.x"
- "1.21.x"

jobs:
tests:
Expand Down
24 changes: 12 additions & 12 deletions build-cs/composer.lock
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions composer.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"phpstan/phpstan": "^1.5",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.5",
"symfony/process": "^5.2"
"phpunit/phpunit": "^10.0",
"symfony/process": "^6.0"
},
"config": {
"platform": {
Expand Down
4 changes: 1 addition & 3 deletions src/Parser/PhpDocParser.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,7 @@ public function parseTagValue(TokenIterator $tokens, string $tag): Ast\PhpDoc\Ph
private function parseParamTagValue(TokenIterator $tokens): Ast\PhpDoc\PhpDocTagValueNode
{
if (
$tokens->isCurrentTokenType(Lexer::TOKEN_REFERENCE)
|| $tokens->isCurrentTokenType(Lexer::TOKEN_VARIADIC)
|| $tokens->isCurrentTokenType(Lexer::TOKEN_VARIABLE)
$tokens->isCurrentTokenType(Lexer::TOKEN_REFERENCE, Lexer::TOKEN_VARIADIC, Lexer::TOKEN_VARIABLE)
) {
$type = null;
} else {
Expand Down
133 changes: 106 additions & 27 deletions src/Parser/TypeParser.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -522,47 +522,126 @@ private function parseCallableReturnType(TokenIterator $tokens): Ast\Type\TypeNo
$startLine = $tokens->currentTokenLine();
$startIndex = $tokens->currentTokenIndex();
if ($tokens->isCurrentTokenType(Lexer::TOKEN_NULLABLE)) {
$type = $this->parseNullable($tokens);
return $this->parseNullable($tokens);

} elseif ($tokens->tryConsumeTokenType(Lexer::TOKEN_OPEN_PARENTHESES)) {
$type = $this->parse($tokens);
$tokens->consumeTokenType(Lexer::TOKEN_CLOSE_PARENTHESES);
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
$type = $this->tryParseArrayOrOffsetAccess($tokens, $type);
}

} else {
$type = new Ast\Type\IdentifierTypeNode($tokens->currentTokenValue());
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);

if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)) {
$type = $this->parseGeneric(
$tokens,
$this->enrichWithAttributes(
$tokens,
$type,
$startLine,
$startIndex
)
);

} elseif (in_array($type->name, ['array', 'list'], true) && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
$type = $this->parseArrayShape($tokens, $this->enrichWithAttributes(
return $type;
} elseif ($tokens->tryConsumeTokenType(Lexer::TOKEN_THIS_VARIABLE)) {
$type = new Ast\Type\ThisTypeNode();
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
$type = $this->tryParseArrayOrOffsetAccess($tokens, $this->enrichWithAttributes(
$tokens,
$type,
$startLine,
$startIndex
), $type->name);
));
}

return $type;
} else {
$currentTokenValue = $tokens->currentTokenValue();
$tokens->pushSavePoint(); // because of ConstFetchNode
if ($tokens->tryConsumeTokenType(Lexer::TOKEN_IDENTIFIER)) {
$type = new Ast\Type\IdentifierTypeNode($currentTokenValue);

if (!$tokens->isCurrentTokenType(Lexer::TOKEN_DOUBLE_COLON)) {
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)) {
$type = $this->parseGeneric(
$tokens,
$this->enrichWithAttributes(
$tokens,
$type,
$startLine,
$startIndex
)
);
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
$type = $this->tryParseArrayOrOffsetAccess($tokens, $this->enrichWithAttributes(
$tokens,
$type,
$startLine,
$startIndex
));
}

} elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
$type = $this->tryParseArrayOrOffsetAccess($tokens, $this->enrichWithAttributes(
$tokens,
$type,
$startLine,
$startIndex
));

} 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);
}

if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
$type = $this->tryParseArrayOrOffsetAccess($tokens, $this->enrichWithAttributes(
$tokens,
$type,
$startLine,
$startIndex
));
}
}

return $type;
} else {
$tokens->rollback(); // because of ConstFetchNode
}
} else {
$tokens->dropSavePoint(); // because of ConstFetchNode
}
}

if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
$type = $this->tryParseArrayOrOffsetAccess($tokens, $this->enrichWithAttributes(
$tokens,
$type,
$startLine,
$startIndex
));
$exception = new ParserException(
$tokens->currentTokenValue(),
$tokens->currentTokenType(),
$tokens->currentTokenOffset(),
Lexer::TOKEN_IDENTIFIER,
null,
$tokens->currentTokenLine()
);

if ($this->constExprParser === null) {
throw $exception;
}

return $type;
try {
$constExpr = $this->constExprParser->parse($tokens, true);
if ($constExpr instanceof Ast\ConstExpr\ConstExprArrayNode) {
throw $exception;
}

$type = new Ast\Type\ConstTypeNode($constExpr);
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
$type = $this->tryParseArrayOrOffsetAccess($tokens, $this->enrichWithAttributes(
$tokens,
$type,
$startLine,
$startIndex
));
}

return $type;
} catch (LogicException $e) {
throw $exception;
}
}


Expand Down
87 changes: 87 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 @@ -770,6 +770,22 @@ public function provideParseData(): array
)
),
],
[
'callable(): Foo<Bar>[]',
new CallableTypeNode(
new IdentifierTypeNode('callable'),
[],
new ArrayTypeNode(new GenericTypeNode(
new IdentifierTypeNode('Foo'),
[
new IdentifierTypeNode('Bar'),
],
[
GenericTypeNode::VARIANCE_INVARIANT,
]
))
),
],
[
'callable(): Foo|Bar',
new UnionTypeNode([
Expand Down Expand Up @@ -1956,6 +1972,77 @@ 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')),
])
)
),
],
[
'callable(): $this',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new ThisTypeNode()),
],
[
'callable(): $this[]',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new ArrayTypeNode(new ThisTypeNode())),
],
[
'2.5|3',
new UnionTypeNode([
new ConstTypeNode(new ConstExprFloatNode('2.5')),
new ConstTypeNode(new ConstExprIntegerNode('3')),
]),
],
[
'callable(): 3.5',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new ConstTypeNode(new ConstExprFloatNode('3.5'))),
],
[
'callable(): 3.5[]',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new ArrayTypeNode(
new ConstTypeNode(new ConstExprFloatNode('3.5'))
)),
],
[
'callable(): Foo',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new IdentifierTypeNode('Foo')),
],
[
'callable(): (Foo)[]',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new ArrayTypeNode(new IdentifierTypeNode('Foo'))),
],
[
'callable(): Foo::BAR',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new ConstTypeNode(new ConstFetchNode('Foo', 'BAR'))),
],
[
'callable(): Foo::*',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new ConstTypeNode(new ConstFetchNode('Foo', '*'))),
],
[
'?Foo[]',
new NullableTypeNode(new ArrayTypeNode(new IdentifierTypeNode('Foo'))),
],
[
'callable(): ?Foo',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new NullableTypeNode(new IdentifierTypeNode('Foo'))),
],
[
'callable(): ?Foo[]',
new CallableTypeNode(new IdentifierTypeNode('callable'), [], new NullableTypeNode(new ArrayTypeNode(new IdentifierTypeNode('Foo')))),
],
];
}

Expand Down
Loading

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