1818use function explode ;
1919use function implode ;
2020use function is_numeric ;
21+ use function is_string ;
2122use function preg_match ;
2223use function sprintf ;
2324use function strpos ;
@@ -87,16 +88,21 @@ public function checkVersionRequirement(array $attributes, array $attrGroups, Sc
8788 continue ;
8889 }
8990
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+
9098 $ versionNode = $ this ->getFixableVersionNode (
9199 $ attributeNodes [$ attr ->getName ()][$ attributeIndex ] ?? null ,
92- $ args ,
100+ $ versionRequirement ,
93101 );
94102
95103 // the following block is mimicing PHPUnit version parsing
96104 // see https://github.com/sebastianbergmann/phpunit/blob/43c2cd7b96ee1e800b35e4df23b419a88b53111d/src/Metadata/Version/Requirement.php
97105
98- $ versionRequirement = $ args [0 ];
99-
100106 if ($ this ->warnAboutIncompleteVersion ($ versionRequirement )) {
101107 $ errorBuilder = RuleErrorBuilder ::message (
102108 sprintf ('Version requirement %s is incomplete. Expect a version composed of major, minor and patch. ' , $ versionRequirement ),
@@ -215,10 +221,8 @@ private function groupAttributeNodesByName(array $attrGroups): array
215221
216222 /**
217223 * Returns the string literal holding the version requirement, when it is a plain literal in the analysed file.
218- *
219- * @param array<int|string, mixed> $args
220224 */
221- private function getFixableVersionNode (?Node \Attribute $ attributeNode , array $ args ): ?String_
225+ private function getFixableVersionNode (?Node \Attribute $ attributeNode , string $ versionRequirement ): ?String_
222226 {
223227 if ($ attributeNode === null || count ($ attributeNode ->args ) !== 1 ) {
224228 return null ;
@@ -230,7 +234,7 @@ private function getFixableVersionNode(?Node\Attribute $attributeNode, array $ar
230234 }
231235
232236 // make sure the AST node is the one the reflection attribute was read from
233- if ($ versionNode ->value !== ( $ args [ 0 ] ?? null ) ) {
237+ if ($ versionNode ->value !== $ versionRequirement ) {
234238 return null ;
235239 }
236240
0 commit comments