Skip to content

Commit

Permalink
Fix composer major.minor version detection (fixes #5415) (#5416)
Browse files Browse the repository at this point in the history
* Fix composer major.minor version detection (fixes #5415)

* Add PHP 8 polyfill dependency.

* Fix version check.
  • Loading branch information
AndrolGenhald authored Mar 18, 2021
1 parent 09ee4c1 commit 45694d3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Psalm/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composer\Autoload\ClassLoader;
use Composer\Semver\Semver;
use Composer\Semver\VersionParser;
use DOMDocument;
use LogicException;
use Psalm\Config\IssueHandler;
Expand Down Expand Up @@ -2053,8 +2054,10 @@ private function getPHPVersionFromComposerJson(): ?string
$php_version = $composer_json['require']['php'] ?? null;

if (\is_string($php_version)) {
$version_parser = new VersionParser();
$min_php_version = $version_parser->parseConstraints($php_version)->getLowerBound()->getVersion();
foreach (['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] as $candidate) {
if (Semver::satisfies($candidate, $php_version)) {
if (Semver::satisfies($min_php_version, "~$candidate.0")) {
return $candidate;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/ComposerPhpVersion/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require": {
"php": "7.2|7.3,<8"
"php": "^7.2.1|7.3,<8"
}
}

0 comments on commit 45694d3

Please sign in to comment.