Skip to content

Commit c86fd8e

Browse files
committed
Tighten match type to drop (string) casts
PatternIterator declared its yielded match as array<mixed>, but preg_match results (no PREG_OFFSET_CAPTURE / PREG_UNMATCHED_AS_NULL) are always string-valued. Declaring array<array-key, string> reflects that guarantee and lets buildQuery() return/concatenate the match values directly, removing the (string) casts. Co-Authored-By: Claude Code
1 parent 7c99c33 commit c86fd8e

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

src/BaseMultiQueryParser.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,15 @@ abstract public function parseStringStream(Iterator $stream): Iterator;
6969
/**
7070
* Builds the yielded query string, prepending captured leading comments when enabled.
7171
*
72-
* @param array<mixed> $match
72+
* @param array<array-key, string> $match
7373
*/
7474
protected function buildQuery(array $match): string
7575
{
76-
$query = (string) $match['query'];
77-
7876
if (!$this->preserveLeadingComments) {
79-
return $query;
77+
return $match['query'];
8078
}
8179

82-
return (string) ($match['leadingComments'] ?? '') . $query;
80+
return ($match['leadingComments'] ?? '') . $match['query'];
8381
}
8482

8583

src/PatternIterator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* the regex engine commits to the construct — if the closing delimiter is missing (because
3131
* it is in a later chunk), the overall match fails, causing the iterator to load more data.
3232
*
33-
* @implements IteratorAggregate<int, array<mixed>>
33+
* @implements IteratorAggregate<int, array<array-key, string>>
3434
*/
3535
class PatternIterator implements IteratorAggregate
3636
{

0 commit comments

Comments
 (0)