-
Notifications
You must be signed in to change notification settings - Fork 461
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
Utilize composer min-php version to narrow PHP_VERSION_ID #3584
Conversation
PHPStan 2.x seems the perfect point in time to re-vive this PR, as it found some dead tests in phpstan-extension repos :) (because of the raised min-php version) |
try { | ||
$composerJsonContents = FileReader::read($composerJsonPath); | ||
$composer = Json::decode($composerJsonContents, Json::FORCE_ARRAY); | ||
$requiredVersion = $composer['require']['php'] ?? null; |
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.
php-64bit
should be supported as well - the minimal version should be used of these two if both are present
This pull request has been marked as ready for review. |
83e59b3
to
1db8700
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.
Now I can finally review it :) Hopefully it makes 2.0, otherwise we'll have to add the bleeding edge toggles again 😂
@@ -0,0 +1,6 @@ | |||
<?php | |||
|
|||
\PHPStan\Testing\assertType('int<80100, max>', PHP_VERSION_ID); |
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.
This could be until 80499 which is the max version allowed in the config. It'd help us prevent more typos and be consistent.
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.
it now takes the max into account.
I have also added the min-version
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.
Do not change anything about the min version. It might seem inconsistent to you, but PHPStan can support analysing PHP 5 codebases without major issues and this would be too annoying.
Please also add E2E tests what would PHPStan think about the PHP_
constants with:
- something like
^5.6
in composer.json. The result should be as precise as possible -meaning 50600-50699 (there was no 5.7) - something like
^7.0
in composer.json. The result should be as precise as possible -meaning 70000-70499 (there was no 7.5)
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 want to limit the min
key in phpstan.neon still to 70100 (because PHPStan doesn't offer any specific logic to lower versions), but I don't want to flag asking for PHP 5 as an error when there's nothing configured about a PHP version in phpstan.neon or composer.json. (Or it's configured in a way that allows for PHP 5, like <=8.3
or ^5.6
)
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.
Hope it's understandable.
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.
Coming to thing of it, there's a 3rd E2E test proposal:
- No version in composer.json, no version in phpstan.neon - assert the
PHP_
constant values.
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 think I adressed everything
not sure what we wanne do with this test: |
Thank you. I'd like a follow up PR - update PHPStanDiagnoseExtension and add information:
|
idea is to catch errors like Roave/BetterReflection#1406 (comment) in which bogus conditions like
if (PHP_VERSION_ID >= 80100) {}
have been used in tests.it's a bug in the linked case, because the project itself only supports
"php": "~8.2.0 || ~8.3.2",
.Since CI only is running against in composer.json declared supported versions this error was not spotted before.
rebased version of #2968 for 2.x