Skip to content

Commit 4a0a51f

Browse files
authored
Improve return type of Str::replace() (#57820)
1 parent 686d479 commit 4a0a51f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Illuminate/Support/Str.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ private static function toStringOr($value, $fallback)
12281228
* @param string|iterable<string> $replace
12291229
* @param string|iterable<string> $subject
12301230
* @param bool $caseSensitive
1231-
* @return string|string[]
1231+
* @return ($subject is string ? string : string[])
12321232
*/
12331233
public static function replace($search, $replace, $subject, $caseSensitive = true)
12341234
{

types/Support/Str.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@
3333
} else {
3434
assertType('mixed', $uuid);
3535
}
36+
37+
/**
38+
* @var string $search
39+
* @var string $replace
40+
* @var string $subject
41+
*/
42+
assertType('string', Str::replace($search, $replace, $subject));
43+
assertType('array<string>', Str::replace($search, $replace, [$subject]));

0 commit comments

Comments
 (0)