Skip to content

Commit a002b7c

Browse files
authored
refactor: fix phpstan no type specified UpdateModelTest (#10016)
* refactor: fix phpstan no type specified UpdateModelTest * use native php type * use DateTimeInterface type
1 parent df5ad3c commit a002b7c

File tree

3 files changed

+36
-143
lines changed

3 files changed

+36
-143
lines changed

tests/system/Models/UpdateModelTest.php

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use CodeIgniter\Entity\Entity;
2020
use CodeIgniter\Exceptions\InvalidArgumentException;
2121
use Config\Database;
22+
use DateTimeInterface;
2223
use PHPUnit\Framework\Attributes\DataProvider;
2324
use PHPUnit\Framework\Attributes\Group;
2425
use stdClass;
@@ -208,13 +209,17 @@ public function testUpdateBatchValidationFail(): void
208209
public function testUpdateBatchWithEntity(): void
209210
{
210211
$entity1 = new class () extends Entity {
211-
protected $id;
212-
protected $name;
213-
protected $email;
214-
protected $country;
215-
protected $deleted;
216-
protected $created_at;
217-
protected $updated_at;
212+
protected int $id;
213+
protected string $name;
214+
protected string $email;
215+
protected string $country;
216+
protected bool $deleted;
217+
protected DateTimeInterface $created_at;
218+
protected DateTimeInterface $updated_at;
219+
220+
/**
221+
* @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}
222+
*/
218223
protected $_options = [
219224
'datamap' => [],
220225
'dates' => [
@@ -227,13 +232,17 @@ public function testUpdateBatchWithEntity(): void
227232
};
228233

229234
$entity2 = new class () extends Entity {
230-
protected $id;
231-
protected $name;
232-
protected $email;
233-
protected $country;
234-
protected $deleted;
235-
protected $created_at;
236-
protected $updated_at;
235+
protected int $id;
236+
protected string $name;
237+
protected string $email;
238+
protected string $country;
239+
protected bool $deleted;
240+
protected DateTimeInterface $created_at;
241+
protected DateTimeInterface $updated_at;
242+
243+
/**
244+
* @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}
245+
*/
237246
protected $_options = [
238247
'datamap' => [],
239248
'dates' => [
@@ -399,13 +408,17 @@ public function testUpdateWithEntityNoAllowedFields(): void
399408
$this->createModel(UserModel::class);
400409

401410
$entity = new class () extends Entity {
402-
protected $id;
403-
protected $name;
404-
protected $email;
405-
protected $country;
406-
protected $deleted;
407-
protected $created_at;
408-
protected $updated_at;
411+
protected int $id;
412+
protected string $name;
413+
protected string $email;
414+
protected string $country;
415+
protected bool $deleted;
416+
protected DateTimeInterface $created_at;
417+
protected DateTimeInterface $updated_at;
418+
419+
/**
420+
* @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}
421+
*/
409422
protected $_options = [
410423
'datamap' => [],
411424
'dates' => [

utils/phpstan-baseline/loader.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 2116 errors
1+
# total 2092 errors
22

33
includes:
44
- argument.type.neon

utils/phpstan-baseline/missingType.property.neon

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 101 errors
1+
# total 77 errors
22

33
parameters:
44
ignoreErrors:
@@ -386,123 +386,3 @@ parameters:
386386
message: '#^Property CodeIgniter\\Model@anonymous/tests/system/Models/SaveModelTest\.php\:290\:\:\$name has no type specified\.$#'
387387
count: 1
388388
path: ../../tests/system/Models/SaveModelTest.php
389-
390-
-
391-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$_options has no type specified\.$#'
392-
count: 1
393-
path: ../../tests/system/Models/UpdateModelTest.php
394-
395-
-
396-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$country has no type specified\.$#'
397-
count: 1
398-
path: ../../tests/system/Models/UpdateModelTest.php
399-
400-
-
401-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$created_at has no type specified\.$#'
402-
count: 1
403-
path: ../../tests/system/Models/UpdateModelTest.php
404-
405-
-
406-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$deleted has no type specified\.$#'
407-
count: 1
408-
path: ../../tests/system/Models/UpdateModelTest.php
409-
410-
-
411-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$email has no type specified\.$#'
412-
count: 1
413-
path: ../../tests/system/Models/UpdateModelTest.php
414-
415-
-
416-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$id has no type specified\.$#'
417-
count: 1
418-
path: ../../tests/system/Models/UpdateModelTest.php
419-
420-
-
421-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$name has no type specified\.$#'
422-
count: 1
423-
path: ../../tests/system/Models/UpdateModelTest.php
424-
425-
-
426-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$updated_at has no type specified\.$#'
427-
count: 1
428-
path: ../../tests/system/Models/UpdateModelTest.php
429-
430-
-
431-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$_options has no type specified\.$#'
432-
count: 1
433-
path: ../../tests/system/Models/UpdateModelTest.php
434-
435-
-
436-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$country has no type specified\.$#'
437-
count: 1
438-
path: ../../tests/system/Models/UpdateModelTest.php
439-
440-
-
441-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$created_at has no type specified\.$#'
442-
count: 1
443-
path: ../../tests/system/Models/UpdateModelTest.php
444-
445-
-
446-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$deleted has no type specified\.$#'
447-
count: 1
448-
path: ../../tests/system/Models/UpdateModelTest.php
449-
450-
-
451-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$email has no type specified\.$#'
452-
count: 1
453-
path: ../../tests/system/Models/UpdateModelTest.php
454-
455-
-
456-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$id has no type specified\.$#'
457-
count: 1
458-
path: ../../tests/system/Models/UpdateModelTest.php
459-
460-
-
461-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$name has no type specified\.$#'
462-
count: 1
463-
path: ../../tests/system/Models/UpdateModelTest.php
464-
465-
-
466-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$updated_at has no type specified\.$#'
467-
count: 1
468-
path: ../../tests/system/Models/UpdateModelTest.php
469-
470-
-
471-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$_options has no type specified\.$#'
472-
count: 1
473-
path: ../../tests/system/Models/UpdateModelTest.php
474-
475-
-
476-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$country has no type specified\.$#'
477-
count: 1
478-
path: ../../tests/system/Models/UpdateModelTest.php
479-
480-
-
481-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$created_at has no type specified\.$#'
482-
count: 1
483-
path: ../../tests/system/Models/UpdateModelTest.php
484-
485-
-
486-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$deleted has no type specified\.$#'
487-
count: 1
488-
path: ../../tests/system/Models/UpdateModelTest.php
489-
490-
-
491-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$email has no type specified\.$#'
492-
count: 1
493-
path: ../../tests/system/Models/UpdateModelTest.php
494-
495-
-
496-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$id has no type specified\.$#'
497-
count: 1
498-
path: ../../tests/system/Models/UpdateModelTest.php
499-
500-
-
501-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$name has no type specified\.$#'
502-
count: 1
503-
path: ../../tests/system/Models/UpdateModelTest.php
504-
505-
-
506-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$updated_at has no type specified\.$#'
507-
count: 1
508-
path: ../../tests/system/Models/UpdateModelTest.php

0 commit comments

Comments
 (0)