@@ -88,20 +88,21 @@ public function checkVersionRequirement(array $attributes, array $attrGroups, Sc
8888 continue ;
8989 }
9090
91+ // phpunit does not support named arguments.
92+ // we handle them here just to make sure we don't crash on them.
93+ $ versionRequirement = $ args [0 ] ?? $ args ['versionRequirement ' ] ?? null ;
94+ if (!is_string ($ versionRequirement )) {
95+ continue ;
96+ }
97+
9198 $ versionNode = $ this ->getFixableVersionNode (
9299 $ attributeNodes [$ attr ->getName ()][$ attributeIndex ] ?? null ,
93- $ args ,
100+ $ versionRequirement ,
94101 );
95102
96103 // the following block is mimicing PHPUnit version parsing
97104 // see https://github.com/sebastianbergmann/phpunit/blob/43c2cd7b96ee1e800b35e4df23b419a88b53111d/src/Metadata/Version/Requirement.php
98105
99- // named arguments are handled just to make sure we don't crash on them.
100- $ versionRequirement = $ args [0 ] ?? $ args ['versionRequirement ' ] ?? null ;
101- if (!is_string ($ versionRequirement )) {
102- continue ;
103- }
104-
105106 if ($ this ->warnAboutIncompleteVersion ($ versionRequirement )) {
106107 $ errorBuilder = RuleErrorBuilder ::message (
107108 sprintf ('Version requirement %s is incomplete. Expect a version composed of major, minor and patch. ' , $ versionRequirement ),
@@ -220,10 +221,8 @@ private function groupAttributeNodesByName(array $attrGroups): array
220221
221222 /**
222223 * Returns the string literal holding the version requirement, when it is a plain literal in the analysed file.
223- *
224- * @param array<int|string, mixed> $args
225224 */
226- private function getFixableVersionNode (?Node \Attribute $ attributeNode , array $ args ): ?String_
225+ private function getFixableVersionNode (?Node \Attribute $ attributeNode , string $ versionRequirement ): ?String_
227226 {
228227 if ($ attributeNode === null || count ($ attributeNode ->args ) !== 1 ) {
229228 return null ;
@@ -235,7 +234,7 @@ private function getFixableVersionNode(?Node\Attribute $attributeNode, array $ar
235234 }
236235
237236 // make sure the AST node is the one the reflection attribute was read from
238- if ($ versionNode ->value !== ( $ args [ 0 ] ?? null ) ) {
237+ if ($ versionNode ->value !== $ versionRequirement ) {
239238 return null ;
240239 }
241240
0 commit comments