Skip to content

Commit

Permalink
Convert constraints into strings consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 6, 2024
1 parent aae3978 commit 2586069
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Composer\Plugin\PluginInterface;
use Composer\Script\Event;
use Composer\Script\ScriptEvents;
use Composer\Semver\Constraint\ConstraintInterface;
use Composer\Semver\Constraint\MultiConstraint;
use Composer\Semver\Intervals;
use Composer\Util\Filesystem;
Expand Down Expand Up @@ -165,7 +166,7 @@ public function process(Event $event): void
'relative_install_path' => $fs->findShortestPath(dirname($generatedConfigFilePath), $absoluteInstallPath, true),
'extra' => $package->getExtra()['phpstan'] ?? null,
'version' => $package->getFullPrettyVersion(),
'phpstanVersionConstraint' => $phpstanConstraint !== null ? (string) $phpstanConstraint : null,
'phpstanVersionConstraint' => $phpstanConstraint !== null ? $this->constraintIntoString($phpstanConstraint) : null,
];

$installedPackages[$package->getName()] = true;
Expand All @@ -178,14 +179,7 @@ public function process(Event $event): void
} else {
$multiConstraint = new MultiConstraint($phpstanVersionConstraints);
}
$compactedConstraint = Intervals::compactConstraint($multiConstraint);
$phpstanVersionConstraint = sprintf(
'%s%s && %s%s',
$compactedConstraint->getLowerBound()->isInclusive() ? '>=' : '>',
$compactedConstraint->getLowerBound()->getVersion(),
$compactedConstraint->getUpperBound()->isInclusive() ? '<=' : '<',
$compactedConstraint->getUpperBound()->getVersion()
);
$phpstanVersionConstraint = $this->constraintIntoString(Intervals::compactConstraint($multiConstraint));
}

ksort($data);
Expand Down Expand Up @@ -214,4 +208,15 @@ public function process(Event $event): void
}
}

private function constraintIntoString(ConstraintInterface $constraint): string
{
return sprintf(
'%s%s && %s%s',
$constraint->getLowerBound()->isInclusive() ? '>=' : '>',
$constraint->getLowerBound()->getVersion(),
$constraint->getUpperBound()->isInclusive() ? '<=' : '<',
$constraint->getUpperBound()->getVersion()
);
}

}

0 comments on commit 2586069

Please sign in to comment.