-
Notifications
You must be signed in to change notification settings - Fork 72
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
Support for nikic/php-parser 5 and psalm 6 #563
Conversation
28270e2
to
de6aa37
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say that patch is a good improvement, but:
- Don't suppress, unless it's an architectural decision: expand baseline or add assertions
- Use a fixed parser syntax, not dependent on environment
@@ -35,6 +35,7 @@ public function __invoke(Traversable $files): Traversable | |||
} | |||
|
|||
try { | |||
/** @psalm-suppress PossiblyFalseArgument */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not suppress here, but either expand baseline, or add a specific exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -273,7 +272,7 @@ private function getComposerData(string $jsonFile): array | |||
private function getASTFromFilesLocator(InputInterface $input): LocateASTFromFiles | |||
{ | |||
$errorHandler = $input->getOption('ignore-parse-errors') ? new CollectingErrorHandler() : null; | |||
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, new Lexer()); | |||
$parser = (new ParserFactory())->createForHostVersion(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use the latest supported syntax, rather than the host syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
/** @var array<string, string> $requires */ | ||
/** | ||
* @var array<string, string> $requires | ||
* @psalm-suppress PossiblyFalseArgument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not suppress: instead either add to baseline or add assertions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
if (property_exists($node, 'namespacedName')) { | ||
$namespacedName = $node->namespacedName; | ||
} | ||
$isNamespacedNameInitialized = (new ReflectionProperty($node, 'namespacedName'))->isInitialized($node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accessing via reflection here is a no-go: we'll get immediate hidden BC breaks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not know how to check here without reflection. Do you have any idea ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably check if there's a better way to access this property: reading an uninitialized property indicates (to me) that we are doing something wrong when talking to the PHP-Parser API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try a solution locally and then merge, no need to touch this further, @tugmaks!
Thanks meanwhile for all the work done thus far! 💪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After much digging, I 100% verified that this is the "API", which kinda sucks, but is an acceptable tradeoff, for now.
...serRequireCheckerTest/FileLocator/LocateComposerPackageDirectDependenciesSourceFilesTest.php
Outdated
Show resolved
Hide resolved
test/ComposerRequireCheckerTest/NodeVisitor/DefinedSymbolCollectorFunctionalTest.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last bit remaining is reflection removal: otherwise, this looks nice!
if (property_exists($node, 'namespacedName')) { | ||
$namespacedName = $node->namespacedName; | ||
} | ||
$isNamespacedNameInitialized = (new ReflectionProperty($node, 'namespacedName'))->isInitialized($node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably check if there's a better way to access this property: reading an uninitialized property indicates (to me) that we are doing something wrong when talking to the PHP-Parser API
if (property_exists($node, 'namespacedName')) { | ||
$namespacedName = $node->namespacedName; | ||
} | ||
$isNamespacedNameInitialized = (new ReflectionProperty($node, 'namespacedName'))->isInitialized($node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try a solution locally and then merge, no need to touch this further, @tugmaks!
Thanks meanwhile for all the work done thus far! 💪
Thanks @tugmaks! |
See https://github.com/nikic/PHP-Parser/blob/master/UPGRADE-5.0.md