|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace ArrayChangeKeyCase; |
| 4 | + |
| 5 | +use function PHPStan\Testing\assertType; |
| 6 | + |
| 7 | +class HelloWorld |
| 8 | +{ |
| 9 | + /** |
| 10 | + * @param array<string> $arr1 |
| 11 | + * @param array<string, string> $arr2 |
| 12 | + * @param array<string|int, string> $arr3 |
| 13 | + * @param array<int, string> $arr4 |
| 14 | + * @param array<lowercase-string, string> $arr5 |
| 15 | + * @param array<lowercase-string&non-falsy-string, string> $arr6 |
| 16 | + * @param array<non-empty-string, string> $arr7 |
| 17 | + * @param array<literal-string, string> $arr8 |
| 18 | + * @param array{foo: 1, bar?: 2} $arr9 |
| 19 | + * @param array<'foo'|'bar', string> $arr10 |
| 20 | + * @param list<string> $list |
| 21 | + * @param non-empty-array<string> $nonEmpty |
| 22 | + */ |
| 23 | + public function sayHello( |
| 24 | + array $arr1, |
| 25 | + array $arr2, |
| 26 | + array $arr3, |
| 27 | + array $arr4, |
| 28 | + array $arr5, |
| 29 | + array $arr6, |
| 30 | + array $arr7, |
| 31 | + array $arr8, |
| 32 | + array $arr9, |
| 33 | + array $arr10, |
| 34 | + array $list, |
| 35 | + array $nonEmpty, |
| 36 | + int $case |
| 37 | + ): void { |
| 38 | + assertType('array<string>', array_change_key_case($arr1)); |
| 39 | + assertType('array<string>', array_change_key_case($arr1, CASE_LOWER)); |
| 40 | + assertType('array<string>', array_change_key_case($arr1, CASE_UPPER)); |
| 41 | + assertType('array<string>', array_change_key_case($arr1, $case)); |
| 42 | + |
| 43 | + assertType('array<lowercase-string, string>', array_change_key_case($arr2)); |
| 44 | + assertType('array<lowercase-string, string>', array_change_key_case($arr2, CASE_LOWER)); |
| 45 | + assertType('array<uppercase-string, string>', array_change_key_case($arr2, CASE_UPPER)); |
| 46 | + assertType('array<string, string>', array_change_key_case($arr2, $case)); |
| 47 | + |
| 48 | + assertType('array<int|lowercase-string, string>', array_change_key_case($arr3)); |
| 49 | + assertType('array<int|lowercase-string, string>', array_change_key_case($arr3, CASE_LOWER)); |
| 50 | + assertType('array<int|uppercase-string, string>', array_change_key_case($arr3, CASE_UPPER)); |
| 51 | + assertType('array<int|string, string>', array_change_key_case($arr3, $case)); |
| 52 | + |
| 53 | + assertType('array<int, string>', array_change_key_case($arr4)); |
| 54 | + assertType('array<int, string>', array_change_key_case($arr4, CASE_LOWER)); |
| 55 | + assertType('array<int, string>', array_change_key_case($arr4, CASE_UPPER)); |
| 56 | + assertType('array<int, string>', array_change_key_case($arr4, $case)); |
| 57 | + |
| 58 | + assertType('array<lowercase-string, string>', array_change_key_case($arr5)); |
| 59 | + assertType('array<lowercase-string, string>', array_change_key_case($arr5, CASE_LOWER)); |
| 60 | + assertType('array<uppercase-string, string>', array_change_key_case($arr5, CASE_UPPER)); |
| 61 | + assertType('array<string, string>', array_change_key_case($arr5, $case)); |
| 62 | + |
| 63 | + assertType('array<lowercase-string&non-falsy-string, string>', array_change_key_case($arr6)); |
| 64 | + assertType('array<lowercase-string&non-falsy-string, string>', array_change_key_case($arr6, CASE_LOWER)); |
| 65 | + assertType('array<non-falsy-string&uppercase-string, string>', array_change_key_case($arr6, CASE_UPPER)); |
| 66 | + assertType('array<non-falsy-string, string>', array_change_key_case($arr6, $case)); |
| 67 | + |
| 68 | + assertType('array<lowercase-string&non-empty-string, string>', array_change_key_case($arr7)); |
| 69 | + assertType('array<lowercase-string&non-empty-string, string>', array_change_key_case($arr7, CASE_LOWER)); |
| 70 | + assertType('array<non-empty-string&uppercase-string, string>', array_change_key_case($arr7, CASE_UPPER)); |
| 71 | + assertType('array<non-empty-string, string>', array_change_key_case($arr7, $case)); |
| 72 | + |
| 73 | + assertType('array<lowercase-string, string>', array_change_key_case($arr8)); |
| 74 | + assertType('array<lowercase-string, string>', array_change_key_case($arr8, CASE_LOWER)); |
| 75 | + assertType('array<uppercase-string, string>', array_change_key_case($arr8, CASE_UPPER)); |
| 76 | + assertType('array<string, string>', array_change_key_case($arr8, $case)); |
| 77 | + |
| 78 | + assertType('array{foo: 1, bar?: 2}', array_change_key_case($arr9)); |
| 79 | + assertType('array{foo: 1, bar?: 2}', array_change_key_case($arr9, CASE_LOWER)); |
| 80 | + assertType('array{FOO: 1, BAR?: 2}', array_change_key_case($arr9, CASE_UPPER)); |
| 81 | + assertType("non-empty-array<'BAR'|'bar'|'FOO'|'foo', 1|2>", array_change_key_case($arr9, $case)); |
| 82 | + |
| 83 | + assertType("array<'bar'|'foo', string>", array_change_key_case($arr10)); |
| 84 | + assertType("array<'bar'|'foo', string>", array_change_key_case($arr10, CASE_LOWER)); |
| 85 | + assertType("array<'BAR'|'FOO', string>", array_change_key_case($arr10, CASE_UPPER)); |
| 86 | + assertType("array<'BAR'|'bar'|'FOO'|'foo', string>", array_change_key_case($arr10, $case)); |
| 87 | + |
| 88 | + assertType('list<string>', array_change_key_case($list)); |
| 89 | + assertType('list<string>', array_change_key_case($list, CASE_LOWER)); |
| 90 | + assertType('list<string>', array_change_key_case($list, CASE_UPPER)); |
| 91 | + assertType('list<string>', array_change_key_case($list, $case)); |
| 92 | + |
| 93 | + assertType('non-empty-array<string>', array_change_key_case($nonEmpty)); |
| 94 | + assertType('non-empty-array<string>', array_change_key_case($nonEmpty, CASE_LOWER)); |
| 95 | + assertType('non-empty-array<string>', array_change_key_case($nonEmpty, CASE_UPPER)); |
| 96 | + assertType('non-empty-array<string>', array_change_key_case($nonEmpty, $case)); |
| 97 | + } |
| 98 | +} |
0 commit comments