@@ -29,10 +29,11 @@ final class AttributeVersionRequirementHelper
2929{
3030
3131 /**
32- * Matches requirements whose version can be completed and given an explicit `>=` operator
33- * without changing their meaning, e.g. `8`, `8.1`, `>=8.1` or `^8.1`.
32+ * Matches requirements whose version can be completed to major.minor.patch
33+ * without changing their meaning, e.g. `>=8`, `>=8.1` or `^8.1`.
34+ * Versions without an operator are deliberately not matched.
3435 */
35- private const FIXABLE_VERSION_REQUIREMENT = '/^(?P<operator>>=|\^)? (?P<space>\s*)(?P<version>\d+(?:\.\d+){0,2})$/ ' ;
36+ private const FIXABLE_VERSION_REQUIREMENT = '/^(?P<operator>>=|\^)(?P<space>\s*)(?P<version>\d+(?:\.\d+){0,2})$/ ' ;
3637
3738 private const VERSION_COMPARISON = "/(?P<operator>!=|<|<=|<>|=|==|>|>=)?\s*(?P<version>[\d\.-]+(dev|(RC|alpha|beta)[\d\.])?)[ \t]* \r?$/m " ;
3839
@@ -183,20 +184,20 @@ public function checkVersionRequirement(array $attributes, array $attrGroups, Sc
183184 }
184185
185186 if ($ this ->PHPUnitVersion ->requiresPhpversionAttributeWithOperator ()->yes ()) {
186- $ errorBuilder = RuleErrorBuilder ::message (
187+ $ errors [] = RuleErrorBuilder ::message (
187188 sprintf ('Version requirement %s is missing operator. ' , $ versionRequirement ),
188189 )
189- ->identifier ('phpunit.attributeRequiresPhpVersion ' );
190- $ errors [] = $ this -> buildError ( $ errorBuilder , $ versionNode );
190+ ->identifier ('phpunit.attributeRequiresPhpVersion ' )
191+ -> build ( );
191192 } elseif (
192193 $ this ->deprecationRulesInstalled
193194 && $ this ->PHPUnitVersion ->deprecatesPhpversionAttributeWithoutOperator ()->yes ()
194195 ) {
195- $ errorBuilder = RuleErrorBuilder ::message (
196+ $ errors [] = RuleErrorBuilder ::message (
196197 sprintf ('Version requirement %s without operator is deprecated. ' , $ versionRequirement ),
197198 )
198- ->identifier ('phpunit.attributeRequiresPhpVersion ' );
199- $ errors [] = $ this -> buildError ( $ errorBuilder , $ versionNode );
199+ ->identifier ('phpunit.attributeRequiresPhpVersion ' )
200+ -> build ( );
200201 }
201202 }
202203 return $ errors ;
@@ -262,22 +263,22 @@ private function buildError(RuleErrorBuilder $errorBuilder, ?String_ $versionNod
262263 }
263264
264265 /**
265- * Completes the version to major.minor.patch and adds the implicit `>=` operator .
266+ * Completes the version to major.minor.patch.
266267 * Only applied where the meaning of the requirement stays the same.
268+ * Versions without an operator are not fixed.
267269 */
268270 private function fixVersionRequirement (string $ versionRequirement ): ?string
269271 {
270272 if (preg_match (self ::FIXABLE_VERSION_REQUIREMENT , $ versionRequirement , $ matches ) !== 1 ) {
271273 return null ;
272274 }
273275
274- $ operator = $ matches ['operator ' ] !== '' ? $ matches ['operator ' ] : '>= ' ;
275276 $ versionParts = explode ('. ' , $ matches ['version ' ]);
276277 while (count ($ versionParts ) < 3 ) {
277278 $ versionParts [] = '0 ' ;
278279 }
279280
280- return $ operator . $ matches ['space ' ] . implode ('. ' , $ versionParts );
281+ return $ matches [ ' operator ' ] . $ matches ['space ' ] . implode ('. ' , $ versionParts );
281282 }
282283
283284 /**
0 commit comments