Skip to content

Commit c6e325a

Browse files
committed
check max php5 and php7 version
1 parent 5d879c8 commit c6e325a

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/Php/ComposerPhpVersionFactory.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private function initializeVersions(): void
7272
$constraint = $parser->parseConstraints($composerPhpVersion);
7373

7474
if (!$constraint->getLowerBound()->isZero()) {
75-
$minVersion = $this->buildVersion($constraint->getLowerBound()->getVersion());
75+
$minVersion = $this->buildVersion($constraint->getLowerBound()->getVersion(), false);
7676

7777
if ($minVersion !== null) {
7878
$this->minVersion = new PhpVersion($minVersion->getVersionId());
@@ -82,7 +82,7 @@ private function initializeVersions(): void
8282
return;
8383
}
8484

85-
$this->maxVersion = $this->buildVersion($constraint->getUpperBound()->getVersion());
85+
$this->maxVersion = $this->buildVersion($constraint->getUpperBound()->getVersion(), true);
8686
}
8787

8888
public function getMinVersion(): ?PhpVersion
@@ -132,9 +132,9 @@ private function getComposerRequireVersion(): ?string
132132
return $composerPhpVersion;
133133
}
134134

135-
private function buildVersion(string $minVersion): ?PhpVersion
135+
private function buildVersion(string $version, bool $isMaxVersion): ?PhpVersion
136136
{
137-
$matches = Strings::match($minVersion, '#^(\d+)\.(\d+)(?:\.(\d+))?#');
137+
$matches = Strings::match($version, '#^(\d+)\.(\d+)(?:\.(\d+))?#');
138138
if ($matches === null) {
139139
return null;
140140
}
@@ -144,7 +144,13 @@ private function buildVersion(string $minVersion): ?PhpVersion
144144
$patch = $matches[3] ?? 0;
145145
$versionId = (int) sprintf('%d%02d%02d', $major, $minor, $patch);
146146

147-
$versionId = min($versionId, PhpVersionFactory::MAX_PHP_VERSION);
147+
if ($isMaxVersion && $version === '6.0.0.0-dev') {
148+
$versionId = min($versionId, PhpVersionFactory::MAX_PHP5_VERSION);
149+
} elseif ($isMaxVersion && $version === '8.0.0.0-dev') {
150+
$versionId = min($versionId, PhpVersionFactory::MAX_PHP7_VERSION);
151+
} else {
152+
$versionId = min($versionId, PhpVersionFactory::MAX_PHP_VERSION);
153+
}
148154

149155
return new PhpVersion($versionId);
150156
}

src/Php/PhpVersionFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ final class PhpVersionFactory
1212

1313
public const MIN_PHP_VERSION = 70100;
1414
public const MAX_PHP_VERSION = 80499;
15+
public const MAX_PHP5_VERSION = 50699;
16+
public const MAX_PHP7_VERSION = 70499;
1517

1618
public function __construct(
1719
private ?int $versionId,

0 commit comments

Comments
 (0)