|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ArrayPad; |
| 4 | + |
| 5 | +use function PHPStan\Testing\assertType; |
| 6 | + |
| 7 | +class HelloWorld |
| 8 | +{ |
| 9 | + /** |
| 10 | + * @param array<string, string> $arrayString |
| 11 | + * @param array<int, int> $arrayInt |
| 12 | + * @param non-empty-array<string, string> $nonEmptyArrayString |
| 13 | + * @param non-empty-array<int, int> $nonEmptyArrayInt |
| 14 | + * @param list<string> $listString |
| 15 | + * @param list<int> $listInt |
| 16 | + * @param non-empty-list<string> $nonEmptyListString |
| 17 | + * @param non-empty-list<int> $nonEmptyListInt |
| 18 | + * @param int $int |
| 19 | + * @param positive-int $positiveInt |
| 20 | + * @param negative-int $negativeInt |
| 21 | + * @param positive-int|negative-int $nonZero |
| 22 | + */ |
| 23 | + public function test( |
| 24 | + $arrayString, |
| 25 | + $arrayInt, |
| 26 | + $nonEmptyArrayString, |
| 27 | + $nonEmptyArrayInt, |
| 28 | + $listString, |
| 29 | + $listInt, |
| 30 | + $nonEmptyListString, |
| 31 | + $nonEmptyListInt, |
| 32 | + $int, |
| 33 | + $positiveInt, |
| 34 | + $negativeInt, |
| 35 | + $nonZero, |
| 36 | + ): void |
| 37 | + { |
| 38 | + assertType('array<int|string, string>', array_pad($arrayString, $int, 'foo')); |
| 39 | + assertType('non-empty-array<int|string, string>', array_pad($arrayString, $positiveInt, 'foo')); |
| 40 | + assertType('non-empty-array<int|string, string>', array_pad($arrayString, $negativeInt, 'foo')); |
| 41 | + assertType('non-empty-array<int|string, string>', array_pad($arrayString, $nonZero, 'foo')); |
| 42 | + |
| 43 | + assertType('array<int, \'foo\'|int>', array_pad($arrayInt, $int, 'foo')); |
| 44 | + assertType('non-empty-array<int, \'foo\'|int>', array_pad($arrayInt, $positiveInt, 'foo')); |
| 45 | + assertType('non-empty-array<int, \'foo\'|int>', array_pad($arrayInt, $negativeInt, 'foo')); |
| 46 | + assertType('non-empty-array<int, \'foo\'|int>', array_pad($arrayInt, $nonZero, 'foo')); |
| 47 | + |
| 48 | + assertType('non-empty-array<int|string, string>', array_pad($nonEmptyArrayString, $int, 'foo')); |
| 49 | + assertType('non-empty-array<int|string, string>', array_pad($nonEmptyArrayString, $positiveInt, 'foo')); |
| 50 | + assertType('non-empty-array<int|string, string>', array_pad($nonEmptyArrayString, $negativeInt, 'foo')); |
| 51 | + assertType('non-empty-array<int|string, string>', array_pad($nonEmptyArrayString, $nonZero, 'foo')); |
| 52 | + |
| 53 | + assertType('non-empty-array<int, \'foo\'|int>', array_pad($nonEmptyArrayInt, $int, 'foo')); |
| 54 | + assertType('non-empty-array<int, \'foo\'|int>', array_pad($nonEmptyArrayInt, $positiveInt, 'foo')); |
| 55 | + assertType('non-empty-array<int, \'foo\'|int>', array_pad($nonEmptyArrayInt, $negativeInt, 'foo')); |
| 56 | + assertType('non-empty-array<int, \'foo\'|int>', array_pad($nonEmptyArrayInt, $nonZero, 'foo')); |
| 57 | + |
| 58 | + assertType('list<string>', array_pad($listString, $int, 'foo')); |
| 59 | + assertType('non-empty-list<string>', array_pad($listString, $positiveInt, 'foo')); |
| 60 | + assertType('non-empty-list<string>', array_pad($listString, $negativeInt, 'foo')); |
| 61 | + assertType('non-empty-list<string>', array_pad($listString, $nonZero, 'foo')); |
| 62 | + |
| 63 | + assertType('list<\'foo\'|int>', array_pad($listInt, $int, 'foo')); |
| 64 | + assertType('non-empty-list<\'foo\'|int>', array_pad($listInt, $positiveInt, 'foo')); |
| 65 | + assertType('non-empty-list<\'foo\'|int>', array_pad($listInt, $negativeInt, 'foo')); |
| 66 | + assertType('non-empty-list<\'foo\'|int>', array_pad($listInt, $nonZero, 'foo')); |
| 67 | + |
| 68 | + assertType('non-empty-list<string>', array_pad($nonEmptyListString, $int, 'foo')); |
| 69 | + assertType('non-empty-list<string>', array_pad($nonEmptyListString, $positiveInt, 'foo')); |
| 70 | + assertType('non-empty-list<string>', array_pad($nonEmptyListString, $negativeInt, 'foo')); |
| 71 | + assertType('non-empty-list<string>', array_pad($nonEmptyListString, $nonZero, 'foo')); |
| 72 | + |
| 73 | + assertType('non-empty-list<\'foo\'|int>', array_pad($nonEmptyListInt, $int, 'foo')); |
| 74 | + assertType('non-empty-list<\'foo\'|int>', array_pad($nonEmptyListInt, $positiveInt, 'foo')); |
| 75 | + assertType('non-empty-list<\'foo\'|int>', array_pad($nonEmptyListInt, $negativeInt, 'foo')); |
| 76 | + assertType('non-empty-list<\'foo\'|int>', array_pad($nonEmptyListInt, $nonZero, 'foo')); |
| 77 | + } |
| 78 | +} |
0 commit comments