|
12 | 12 | */ |
13 | 13 | class InvalidKeyInArrayDimFetchRuleTest extends RuleTestCase |
14 | 14 | { |
| 15 | + private bool $reportCastedArrayKey = false; |
15 | 16 |
|
16 | 17 | protected function getRule(): Rule |
17 | 18 | { |
18 | 19 | $ruleLevelHelper = new RuleLevelHelper($this->createReflectionProvider(), true, false, true, false, false, false, true); |
19 | | - return new InvalidKeyInArrayDimFetchRule($ruleLevelHelper, true); |
| 20 | + return new InvalidKeyInArrayDimFetchRule($ruleLevelHelper, true, $this->reportCastedArrayKey); |
20 | 21 | } |
21 | 22 |
|
22 | 23 | public function testInvalidKey(): void |
@@ -61,6 +62,69 @@ public function testInvalidKey(): void |
61 | 62 | ]); |
62 | 63 | } |
63 | 64 |
|
| 65 | + public function testInvalidKeyReportingCastedArrayKey(): void |
| 66 | + { |
| 67 | + $this->reportCastedArrayKey = true; |
| 68 | + $this->analyse([__DIR__ . '/data/invalid-key-array-dim-fetch.php'], [ |
| 69 | + [ |
| 70 | + 'Invalid array key type null.', |
| 71 | + 6, |
| 72 | + ], |
| 73 | + [ |
| 74 | + 'Invalid array key type DateTimeImmutable.', |
| 75 | + 7, |
| 76 | + ], |
| 77 | + [ |
| 78 | + 'Invalid array key type array.', |
| 79 | + 8, |
| 80 | + ], |
| 81 | + [ |
| 82 | + 'Invalid array key type float.', |
| 83 | + 10, |
| 84 | + ], |
| 85 | + [ |
| 86 | + 'Invalid array key type true.', |
| 87 | + 12, |
| 88 | + ], |
| 89 | + [ |
| 90 | + 'Invalid array key type false.', |
| 91 | + 13, |
| 92 | + ], |
| 93 | + [ |
| 94 | + 'Possibly invalid array key type string|null.', |
| 95 | + 17, |
| 96 | + ], |
| 97 | + [ |
| 98 | + 'Possibly invalid array key type stdClass|string.', |
| 99 | + 24, |
| 100 | + ], |
| 101 | + [ |
| 102 | + 'Invalid array key type DateTimeImmutable.', |
| 103 | + 31, |
| 104 | + ], |
| 105 | + [ |
| 106 | + 'Invalid array key type DateTimeImmutable.', |
| 107 | + 45, |
| 108 | + ], |
| 109 | + [ |
| 110 | + 'Invalid array key type DateTimeImmutable.', |
| 111 | + 46, |
| 112 | + ], |
| 113 | + [ |
| 114 | + 'Invalid array key type DateTimeImmutable.', |
| 115 | + 47, |
| 116 | + ], |
| 117 | + [ |
| 118 | + 'Invalid array key type stdClass.', |
| 119 | + 47, |
| 120 | + ], |
| 121 | + [ |
| 122 | + 'Invalid array key type DateTimeImmutable.', |
| 123 | + 48, |
| 124 | + ], |
| 125 | + ]); |
| 126 | + } |
| 127 | + |
64 | 128 | public function testBug6315(): void |
65 | 129 | { |
66 | 130 | if (PHP_VERSION_ID < 80100) { |
@@ -95,4 +159,20 @@ public function testBug6315(): void |
95 | 159 | ]); |
96 | 160 | } |
97 | 161 |
|
| 162 | + public function testUnsetFalseKey(): void |
| 163 | + { |
| 164 | + $this->reportCastedArrayKey = true; |
| 165 | + |
| 166 | + $this->analyse([__DIR__ . '/data/unset-false-key.php'], [ |
| 167 | + [ |
| 168 | + 'Invalid array key type false.', |
| 169 | + 6, |
| 170 | + ], |
| 171 | + [ |
| 172 | + 'Invalid array key type false.', |
| 173 | + 13, |
| 174 | + ], |
| 175 | + ]); |
| 176 | + } |
| 177 | + |
98 | 178 | } |
0 commit comments