Skip to content

Commit 2586069

Browse files
committed
Convert constraints into strings consistently
1 parent aae3978 commit 2586069

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/Plugin.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Composer\Plugin\PluginInterface;
99
use Composer\Script\Event;
1010
use Composer\Script\ScriptEvents;
11+
use Composer\Semver\Constraint\ConstraintInterface;
1112
use Composer\Semver\Constraint\MultiConstraint;
1213
use Composer\Semver\Intervals;
1314
use Composer\Util\Filesystem;
@@ -165,7 +166,7 @@ public function process(Event $event): void
165166
'relative_install_path' => $fs->findShortestPath(dirname($generatedConfigFilePath), $absoluteInstallPath, true),
166167
'extra' => $package->getExtra()['phpstan'] ?? null,
167168
'version' => $package->getFullPrettyVersion(),
168-
'phpstanVersionConstraint' => $phpstanConstraint !== null ? (string) $phpstanConstraint : null,
169+
'phpstanVersionConstraint' => $phpstanConstraint !== null ? $this->constraintIntoString($phpstanConstraint) : null,
169170
];
170171

171172
$installedPackages[$package->getName()] = true;
@@ -178,14 +179,7 @@ public function process(Event $event): void
178179
} else {
179180
$multiConstraint = new MultiConstraint($phpstanVersionConstraints);
180181
}
181-
$compactedConstraint = Intervals::compactConstraint($multiConstraint);
182-
$phpstanVersionConstraint = sprintf(
183-
'%s%s && %s%s',
184-
$compactedConstraint->getLowerBound()->isInclusive() ? '>=' : '>',
185-
$compactedConstraint->getLowerBound()->getVersion(),
186-
$compactedConstraint->getUpperBound()->isInclusive() ? '<=' : '<',
187-
$compactedConstraint->getUpperBound()->getVersion()
188-
);
182+
$phpstanVersionConstraint = $this->constraintIntoString(Intervals::compactConstraint($multiConstraint));
189183
}
190184

191185
ksort($data);
@@ -214,4 +208,15 @@ public function process(Event $event): void
214208
}
215209
}
216210

211+
private function constraintIntoString(ConstraintInterface $constraint): string
212+
{
213+
return sprintf(
214+
'%s%s && %s%s',
215+
$constraint->getLowerBound()->isInclusive() ? '>=' : '>',
216+
$constraint->getLowerBound()->getVersion(),
217+
$constraint->getUpperBound()->isInclusive() ? '<=' : '<',
218+
$constraint->getUpperBound()->getVersion()
219+
);
220+
}
221+
217222
}

0 commit comments

Comments
 (0)