GeezerVison is showing github.com — TypeParser - Handle union on nullable by Korbeil · Pull Request #86 · phpstan/phpdoc-parser
Conversation
Korbeil
commented
Oct 26, 2021
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
I was working on symfony/symfony#40457 to introduce this parser as the default extractor for Symfony. And one of the actual tests (https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php#L86-L89) contains a PhpDoc with @var ?string|int.
And the only remaining issue I have on this extractor is that PhpStan can't parse correctly nullable union types !
Here is the output with the latest version of phpstan/phpdoc-parser:
^ PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode^ {#358
+children: array:1 [
0 => PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode^ {#316
+name: "@var"
+value: PHPStan\PhpDocParser\Ast\PhpDoc\InvalidTagValueNode^ {#399
+value: "?string|int"
+exception: PHPStan\PhpDocParser\Parser\ParserException^ {#398
-currentTokenValue: "|"
-currentTokenType: 1
-currentOffset: 23
-expectedTokenType: 27
#message: "Unexpected token "|", expected TOKEN_OTHER at offset 23"
#code: 0
#file: "./vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php"
#line: 183
trace: {
./vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php:183 { …}
./vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php:80 { …}
./vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php:438 { …}
./vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php:220 { …}
./vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php:113 { …}
./vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php:92 { …}
./vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php:53 { …}
./vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php:38 { …}
./src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php:233 {
Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor->getDocBlockFromProperty(string $class, string $property): PhpDocNode^
› $tokens = new TokenIterator($this->lexer->tokenize($rawDocNode));
› $phpDocNode = $this->phpDocParser->parse($tokens);
› dd($phpDocNode);
}
./src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php:199 { …}
./src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php:73 { …}
./src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php:184 { …}
./.phpunit/phpunit-9.5-0/src/Framework/TestCase.php:1528 { …}
./.phpunit/phpunit-9.5-0/src/Framework/TestCase.php:1134 { …}
./.phpunit/phpunit-9.5-0/src/Framework/TestResult.php:722 { …}
./.phpunit/phpunit-9.5-0/src/Framework/TestCase.php:886 { …}
./.phpunit/phpunit-9.5-0/src/Framework/TestSuite.php:678 { …}
./.phpunit/phpunit-9.5-0/src/Framework/TestSuite.php:678 { …}
./.phpunit/phpunit-9.5-0/src/Framework/TestSuite.php:678 { …}
./.phpunit/phpunit-9.5-0/src/TextUI/TestRunner.php:670 { …}
./.phpunit/phpunit-9.5-0/src/TextUI/Command.php:143 { …}
./.phpunit/phpunit-9.5-0/src/TextUI/Command.php:96 { …}
./.phpunit/phpunit-9.5-0/phpunit:22 { …}
./vendor/symfony/phpunit-bridge/bin/simple-phpunit.php:430 { …}
./vendor/symfony/phpunit-bridge/bin/simple-phpunit:13 { …}
./phpunit:28 { …}
}
}
}
}
]
}
So this PR introduce a fix to make this parser work correctly with nullable union types
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
I didn't tested it and now I see that is no valid syntax (see https://3v4l.org/r7KOM) so I can understand the 👎
So I'm not sure if I should keep this PR open, I'll think about it and come back later 😅
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Yeah, it's definitely better to update the Symfony code in this case.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Korbeil
commented
Oct 27, 2021
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Closing this PR as this is no valid PHP syntax, we'll just ignore this syntax in the Symfony extractor.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.