Skip to content

Commit 4b2e01a

Browse files
author
Sébastien Nikolaou
authored
[10.x] Add generic typehints to collections returned from Stringable methods (#46702)
* Add generic typehints to collections returned from `Stringable` methods * Test types for Stringable methods that return collections
1 parent 2e07695 commit 4b2e01a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/Illuminate/Support/Stringable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public function excerpt($phrase = '', $options = [])
254254
*
255255
* @param string $delimiter
256256
* @param int $limit
257-
* @return \Illuminate\Support\Collection
257+
* @return \Illuminate\Support\Collection<int, string>
258258
*/
259259
public function explode($delimiter, $limit = PHP_INT_MAX)
260260
{
@@ -267,7 +267,7 @@ public function explode($delimiter, $limit = PHP_INT_MAX)
267267
* @param string|int $pattern
268268
* @param int $limit
269269
* @param int $flags
270-
* @return \Illuminate\Support\Collection
270+
* @return \Illuminate\Support\Collection<int, string>
271271
*/
272272
public function split($pattern, $limit = -1, $flags = 0)
273273
{
@@ -909,7 +909,7 @@ public function ucfirst()
909909
/**
910910
* Split a string by uppercase characters.
911911
*
912-
* @return \Illuminate\Support\Collection
912+
* @return \Illuminate\Support\Collection<int, string>
913913
*/
914914
public function ucsplit()
915915
{

types/Support/Stringable.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use Illuminate\Support\Stringable;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
$stringable = new Stringable();
8+
9+
assertType('Illuminate\Support\Collection<int, string>', $stringable->explode(''));
10+
11+
assertType('Illuminate\Support\Collection<int, string>', $stringable->split(1));
12+
13+
assertType('Illuminate\Support\Collection<int, string>', $stringable->ucsplit());

0 commit comments

Comments
 (0)