Skip to content

Commit 38c1c79

Browse files
authored
refactor: Fix phpstan errors offsetAccess.notFound (codeigniter4#9486)
1 parent 884412c commit 38c1c79

File tree

4 files changed

+33
-53
lines changed

4 files changed

+33
-53
lines changed

tests/system/Models/DataConverterModelTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testFindAsArray(): void
3636

3737
$user = $this->model->find($id);
3838

39-
$this->assertIsInt($user['id']);
39+
$this->assertIsInt($user['id']); // @phpstan-ignore offsetAccess.notFound
4040
$this->assertInstanceOf(Time::class, $user['created_at']);
4141
$this->assertSame('John Smith', $user['name']);
4242
// `name` is cast by custom CastBase64 handler.
@@ -128,9 +128,9 @@ public function testFindAllAsArray(): void
128128

129129
$users = $this->model->findAll();
130130

131-
$this->assertIsInt($users[0]['id']);
131+
$this->assertIsInt($users[0]['id']); // @phpstan-ignore offsetAccess.notFound
132132
$this->assertInstanceOf(Time::class, $users[0]['created_at']);
133-
$this->assertIsInt($users[1]['id']);
133+
$this->assertIsInt($users[1]['id']); // @phpstan-ignore offsetAccess.notFound
134134
$this->assertInstanceOf(Time::class, $users[1]['created_at']);
135135
}
136136

@@ -208,7 +208,7 @@ public function testFirstAsArray(): void
208208

209209
$user = $this->model->first();
210210

211-
$this->assertIsInt($user['id']);
211+
$this->assertIsInt($user['id']); // @phpstan-ignore offsetAccess.notFound
212212
$this->assertInstanceOf(Time::class, $user['created_at']);
213213
}
214214

@@ -264,7 +264,8 @@ public function testInsertArray(): void
264264
$id = $this->model->insert($data, true);
265265

266266
$user = $this->model->find($id);
267-
$this->assertSame(['[email protected]'], $user['email']);
267+
268+
$this->assertSame(['[email protected]'], $user['email']); // @phpstan-ignore offsetAccess.notFound
268269
}
269270

270271
public function testInsertObject(): void
@@ -279,7 +280,8 @@ public function testInsertObject(): void
279280
$id = $this->model->insert($data, true);
280281

281282
$user = $this->model->find($id);
282-
$this->assertSame(['[email protected]'], $user['email']);
283+
284+
$this->assertSame(['[email protected]'], $user['email']); // @phpstan-ignore offsetAccess.notFound
283285
}
284286

285287
public function testUpdateArray(): void
@@ -288,14 +290,14 @@ public function testUpdateArray(): void
288290
$user = $this->model->find($id);
289291

290292
$user['email'][] = '[email protected]';
291-
$this->model->update($user['id'], $user);
293+
$this->model->update($user['id'], $user); // @phpstan-ignore offsetAccess.notFound
292294

293295
$user = $this->model->find($id);
294296

295297
$this->assertSame([
296298
297299
298-
], $user['email']);
300+
], $user['email']); // @phpstan-ignore offsetAccess.notFound
299301
}
300302

301303
public function testUpdateObject(): void
@@ -311,7 +313,7 @@ public function testUpdateObject(): void
311313
$this->assertSame([
312314
313315
314-
], $user['email']);
316+
], $user['email']); // @phpstan-ignore offsetAccess.notFound
315317
}
316318

317319
public function testUpdateCustomObject(): void
@@ -363,7 +365,7 @@ public function testSaveArray(): void
363365
$this->assertSame([
364366
365367
366-
], $user['email']);
368+
], $user['email']); // @phpstan-ignore offsetAccess.notFound
367369
}
368370

369371
public function testSaveObject(): void
@@ -379,7 +381,7 @@ public function testSaveObject(): void
379381
$this->assertSame([
380382
381383
382-
], $user['email']);
384+
], $user['email']); // @phpstan-ignore offsetAccess.notFound
383385
}
384386

385387
public function testSaveCustomObject(): void

tests/system/Models/TimestampModelTest.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ public function testDoNotAllowDatesInsertArrayWithoutDatesSetsTimestamp(): void
9393
$user = $this->model->find($id);
9494

9595
$expected = '2023-11-25 12:00:00';
96+
9697
if ($this->db->DBDriver === 'SQLSRV') {
9798
$expected .= '.000';
9899
}
99-
$this->assertSame($expected, $user['created_at']);
100+
101+
$this->assertSame($expected, $user['created_at']); // @phpstan-ignore offsetAccess.notFound
100102
$this->assertSame($expected, $user['updated_at']);
101103
}
102104

@@ -116,10 +118,12 @@ public function testDoNotAllowDatesInsertArrayWithDatesSetsTimestamp(): void
116118
$user = $this->model->find($id);
117119

118120
$expected = '2023-11-25 12:00:00';
121+
119122
if ($this->db->DBDriver === 'SQLSRV') {
120123
$expected .= '.000';
121124
}
122-
$this->assertSame($expected, $user['created_at']);
125+
126+
$this->assertSame($expected, $user['created_at']); // @phpstan-ignore offsetAccess.notFound
123127
$this->assertSame($expected, $user['updated_at']);
124128
}
125129

@@ -139,15 +143,17 @@ public function testDoNotAllowDatesUpdateArrayUpdatesUpdatedAt(): void
139143
$user = $this->model->find($id);
140144

141145
$user['country'] = 'CA';
142-
$this->model->update($user['id'], $user);
146+
$this->model->update($user['id'], $user); // @phpstan-ignore offsetAccess.notFound
143147

144148
$user = $this->model->find($id);
145149

146150
$expected = '2023-11-25 12:00:00';
151+
147152
if ($this->db->DBDriver === 'SQLSRV') {
148153
$expected .= '.000';
149154
}
150-
$this->assertSame($expected, $user['created_at']);
155+
156+
$this->assertSame($expected, $user['created_at']); // @phpstan-ignore offsetAccess.notFound
151157
$this->assertSame($expected, $user['updated_at']);
152158
}
153159

@@ -197,10 +203,12 @@ public function testAllowDatesInsertArrayWithoutDatesSetsTimestamp(): void
197203
$user = $this->model->find($id);
198204

199205
$expected = '2023-11-25 12:00:00';
206+
200207
if ($this->db->DBDriver === 'SQLSRV') {
201208
$expected .= '.000';
202209
}
203-
$this->assertSame($expected, $user['created_at']);
210+
211+
$this->assertSame($expected, $user['created_at']); // @phpstan-ignore offsetAccess.notFound
204212
$this->assertSame($expected, $user['updated_at']);
205213
}
206214

@@ -224,10 +232,12 @@ public function testAllowDatesInsertArrayWithDatesSetsTimestamp(): void
224232
$user = $this->model->find($id);
225233

226234
$expected = '2000-01-01 12:00:00';
235+
227236
if ($this->db->DBDriver === 'SQLSRV') {
228237
$expected .= '.000';
229238
}
230-
$this->assertSame($expected, $user['created_at']);
239+
240+
$this->assertSame($expected, $user['created_at']); // @phpstan-ignore offsetAccess.notFound
231241
$this->assertSame($expected, $user['updated_at']);
232242
}
233243

@@ -251,15 +261,17 @@ public function testAllowDatesUpdateArrayUpdatesUpdatedAt(): void
251261
$user = $this->model->find($id);
252262

253263
$user['country'] = 'CA';
254-
$this->model->update($user['id'], $user);
264+
$this->model->update($user['id'], $user); // @phpstan-ignore offsetAccess.notFound
255265

256266
$user = $this->model->find($id);
257267

258268
$expected = '2000-01-01 12:00:00';
269+
259270
if ($this->db->DBDriver === 'SQLSRV') {
260271
$expected .= '.000';
261272
}
262-
$this->assertSame($expected, $user['created_at']);
273+
274+
$this->assertSame($expected, $user['created_at']); // @phpstan-ignore offsetAccess.notFound
263275
$this->assertSame($expected, $user['updated_at']);
264276
}
265277

utils/phpstan-baseline/loader.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ includes:
2626
- notIdentical.alwaysTrue.neon
2727
- nullCoalesce.property.neon
2828
- nullCoalesce.variable.neon
29-
- offsetAccess.notFound.neon
3029
- parameterByRef.unusedType.neon
3130
- property.defaultValue.neon
3231
- property.nonObject.neon

utils/phpstan-baseline/offsetAccess.notFound.neon

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)