88use Composer \Plugin \PluginInterface ;
99use Composer \Script \Event ;
1010use Composer \Script \ScriptEvents ;
11+ use Composer \Semver \Constraint \ConstraintInterface ;
1112use Composer \Semver \Constraint \MultiConstraint ;
1213use Composer \Semver \Intervals ;
1314use 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