-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Narrow explode return to constant arrays for small positive limits
- Loading branch information
Showing
4 changed files
with
90 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php // lint < 8.0 | ||
|
||
namespace ExplodePhp7; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @param non-empty-string $nonEmptyString | ||
*/ | ||
public function constantArrays(string $string, string $nonEmptyString): void | ||
{ | ||
$strings = explode(',', $string, 0); | ||
assertType('array{string}', $strings); | ||
|
||
$strings = explode(',', $string, 2); | ||
assertType('array{0: string, 1?: string}', $strings); | ||
|
||
$strings = explode(rand(0, 1) ? '' : ',', $string, 2); | ||
assertType('array{0: string, 1?: string}|false', $strings); | ||
|
||
$strings = explode(',', $string, 16); | ||
assertType('non-empty-list<string>', $strings); | ||
|
||
$strings = explode(',', $nonEmptyString, 2); | ||
assertType('array{0: string, 1?: string}', $strings); | ||
|
||
$strings = explode(',', $nonEmptyString, 16); | ||
assertType('non-empty-list<string>', $strings); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php // lint >= 8.0 | ||
|
||
namespace ExplodePhp8; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @param non-empty-string $nonEmptyString | ||
*/ | ||
public function constantArrays(string $string, string $nonEmptyString): void | ||
{ | ||
$strings = explode(',', $string, 0); | ||
assertType('array{string}', $strings); | ||
|
||
$strings = explode(',', $string, 2); | ||
assertType('array{0: string, 1?: string}', $strings); | ||
|
||
$strings = explode(rand(0, 1) ? '' : ',', $string, 2); | ||
assertType('array{0: string, 1?: string}', $strings); | ||
|
||
$strings = explode(',', $string, 16); | ||
assertType('non-empty-list<string>', $strings); | ||
|
||
$strings = explode(',', $nonEmptyString, 2); | ||
assertType('array{0: string, 1?: string}', $strings); | ||
|
||
$strings = explode(',', $nonEmptyString, 16); | ||
assertType('non-empty-list<string>', $strings); | ||
} | ||
|
||
} |