|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace NonEmptyStringSubstr; |
| 4 | + |
| 5 | +use function PHPStan\Testing\assertType; |
| 6 | + |
| 7 | +class Foo |
| 8 | +{ |
| 9 | + |
| 10 | + /** |
| 11 | + * @param non-empty-string $nonEmpty |
| 12 | + * @param positive-int $positiveInt |
| 13 | + * @param 1|2|3 $postiveRange |
| 14 | + * @param -1|-2|-3 $negativeRange |
| 15 | + */ |
| 16 | + public function doSubstr(string $s, $nonEmpty, $positiveInt, $postiveRange, $negativeRange): void |
| 17 | + { |
| 18 | + assertType('(string|false)', substr($s, 5)); |
| 19 | + |
| 20 | + assertType('(string|false)', substr($s, -5)); |
| 21 | + assertType('non-empty-string', substr($nonEmpty, -5)); |
| 22 | + assertType('non-empty-string', substr($nonEmpty, $negativeRange)); |
| 23 | + |
| 24 | + assertType('(string|false)', substr($s, 0, 5)); |
| 25 | + assertType('non-empty-string', substr($nonEmpty, 0, 5)); |
| 26 | + assertType('non-empty-string', substr($nonEmpty, 0, $postiveRange)); |
| 27 | + |
| 28 | + assertType('(string|false)', substr($nonEmpty, 0, -5)); |
| 29 | + |
| 30 | + assertType('(string|false)', substr($s, 0, $positiveInt)); |
| 31 | + assertType('non-empty-string', substr($nonEmpty, 0, $positiveInt)); |
| 32 | + } |
| 33 | + |
| 34 | +} |
0 commit comments