Skip to content
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

Merged
merged 2 commits into from
Feb 6, 2025

Conversation

tugmaks
Copy link
Contributor

@tugmaks tugmaks commented Feb 6, 2025

@tugmaks tugmaks force-pushed the parser5-and-psalm6 branch from 28270e2 to de6aa37 Compare February 6, 2025 12:16
Copy link
Collaborator

@Ocramius Ocramius left a 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 */
Copy link
Collaborator

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

Copy link
Contributor Author

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();
Copy link
Collaborator

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

Copy link
Contributor Author

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
Copy link
Collaborator

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

Copy link
Contributor Author

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);
Copy link
Collaborator

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

Copy link
Contributor Author

@tugmaks tugmaks Feb 6, 2025

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 ?

Copy link
Collaborator

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

Copy link
Collaborator

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! 💪

Copy link
Collaborator

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.

test/ComposerRequireCheckerTest/Cli/OptionsTest.php Outdated Show resolved Hide resolved
@tugmaks tugmaks requested a review from Ocramius February 6, 2025 13:47
Copy link
Collaborator

@Ocramius Ocramius left a 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);
Copy link
Collaborator

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);
Copy link
Collaborator

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! 💪

@Ocramius Ocramius self-assigned this Feb 6, 2025
@Ocramius Ocramius added enhancement dependencies Pull requests that update a dependency file labels Feb 6, 2025
@Ocramius Ocramius added this to the 4.16.0 milestone Feb 6, 2025
@Ocramius Ocramius merged commit 9239527 into maglnet:4.16.x Feb 6, 2025
25 checks passed
@Ocramius
Copy link
Collaborator

Ocramius commented Feb 6, 2025

Thanks @tugmaks!

@tugmaks tugmaks deleted the parser5-and-psalm6 branch February 6, 2025 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants