Repository navigation
Respect exclusive bounds of the composer.json php constraint in ComposerPhpVersionParser - #7153
phpstan-bot wants to merge 3 commits into
Conversation
…mposerPhpVersionParser` - Pass `Bound::isInclusive()` of the lower and upper bound into `buildVersion()`. - An exclusive upper bound now yields the previous version ID (`<8.5.2` -> 8.5.1, `8.4.*` / `<8.5.0.0-dev` -> 8.4.99), unless a non-zero 4th version component keeps the patch version itself allowed (`<8.5.2.1` -> 8.5.2). - An exclusive lower bound now yields the next version ID (`>8.2.3` -> 8.2.4), unless it carries a stability suffix (`>8.2.3-beta` still allows stable 8.2.3). - Existing clamping of `^5.x`/`^7.x` upper bounds to MAX_PHP5/MAX_PHP7 and of everything to MAX_PHP_VERSION is unchanged. - ExtensionVersionProvider, the only other place reading semver bounds, already checks `isInclusive()`; `PhpVersionFactory` parses an exact platform version, not a constraint, so it is not affected.
…f the composer.json `php` constraint Only an upper bound normalized to `X.Y.Z.0-dev` excludes every PHP_VERSION_ID of X.Y.Z. `<8.5.0-RC1` still allows 8.5.0-beta and `<8.5.2-stable` still allows 8.5.2-RC1, which share the version ID of the release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…0.15` Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
#7115 and this PR fix the same thing in nearly the same way: an exclusive lower bound adds one to the version ID, an exclusive upper bound subtracts one. Comparing them turned up two problems with this PR, and I've fixed both. 1. Two prerelease edge cases where #7115 was right. I ran all 22 of #7115's test constraints against this PR's code; 20 gave the same result. The other two:
A prerelease has the same 2. An e2e test this PR broke. What still differs:
The results now match, so it's mostly about which PR you'd rather credit. #7115 is an outside contribution that was already open and got the prerelease cases right first, so merging it and closing this one would be reasonable. I made two commits on top of the branch, not pushed:
|
|
I think we should go with #7115 - @VincentLanglet any strong feelings on your end? |
|
I'm ok with it |
Summary
The PHP version range derived from the
require.phpconstraint incomposer.jsonignored whether the composer-semver bounds were inclusive or exclusive.>8.2.3 <8.5.2was reported as8.2.3-8.5.2, and the very common8.4.*(or~8.4.0,>=8.1 <8.3, ...) resulted in a max version of8.5, soPHP_VERSION_IDbecameint<80400, 80500>.Changes
src/Php/ComposerPhpVersionParser.php: passBound::isInclusive()intobuildVersion()and adjust the version ID by one for exclusive bounds:<8.5.2→ 8.5.1,<8.5.0.0-dev→ 8.4.99), except when a non-zero 4th component still allows the patch version (<8.5.2.1→ 8.5.2);>8.2.3→ 8.2.4), except when it carries a stability suffix (>8.2.3-betastill allows 8.2.3).ExtensionVersionProvideralready checksisInclusive()on the upper bound;PhpVersionFactoryhandlesconfig.platform.php, which is an exact version, not a range. No changes needed there.Root cause
ComposerPhpVersionParserread onlyBound::getVersion()and treated every bound as inclusive. Composer expresses8.4.*as>=8.4.0.0-dev <8.5.0.0-devand>8.2.3as an exclusive8.2.3.0bound, so the excluded endpoint ended up inside the analysed range.Test
New
tests/PHPStan/Php/ComposerPhpVersionFactoryTest.phpwrites a temporarycomposer.jsonfor each constraint and checks the resulting min/max version IDs. It covers the issue's constraint,8.4.*,~8.1.0,>=8.1 <8.3,<8.4, inclusive bounds, patch rollover (>8.2.99), stability suffixes, 4-component versions, and the existing PHP 5/7/max clamping. Six of these cases fail without the fix.Fixes phpstan/phpstan#15777