Skip to content

Commit 67c1243

Browse files
committed
Add support for numerically indexed array generics.
1 parent 56cec45 commit 67c1243

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

custom-standards/Flyeralarm/Sniffs/Docblock/ReturnTypeSniff.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ private function checkReturnTypeShape(string $subject)
160160
}
161161

162162
$match = trim($match);
163+
if (strpos($match, 'int,') === 0) {
164+
// Allow numeric indexing in generics, e.g. `array<int, string>`
165+
$match = substr($match, 4);
166+
}
167+
163168
if ($match === '') {
164169
throw new \InvalidArgumentException('Generic specification may not be empty in type "' . $matches[0][$index] . '"');
165170
}

tests/rules/doc/allowed/ReturnTypeArrayGenerics.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ public function testWithGeneric()
2020
{
2121
}
2222

23+
/**
24+
* @return array<int, string>
25+
*/
26+
public function testWithNumericIndex()
27+
{
28+
}
29+
2330
/**
2431
* @return array<string | int>
2532
*/

0 commit comments

Comments
 (0)