From 03cc8b18d5c2ccdb4dd0be6397c4815be987f821 Mon Sep 17 00:00:00 2001 From: Adi Prasetyo Date: Mon, 2 Mar 2026 22:04:51 +0700 Subject: [PATCH 1/3] refactor: fix phpstan no type specified UpdateModelTest --- tests/system/Models/UpdateModelTest.php | 93 +++++++++++++ utils/phpstan-baseline/loader.neon | 2 +- .../missingType.property.neon | 122 +----------------- 3 files changed, 95 insertions(+), 122 deletions(-) diff --git a/tests/system/Models/UpdateModelTest.php b/tests/system/Models/UpdateModelTest.php index 7f0f6dd98527..7bc09eec2fc8 100644 --- a/tests/system/Models/UpdateModelTest.php +++ b/tests/system/Models/UpdateModelTest.php @@ -208,13 +208,44 @@ public function testUpdateBatchValidationFail(): void public function testUpdateBatchWithEntity(): void { $entity1 = new class () extends Entity { + /** + * @var int + */ protected $id; + + /** + * @var string + */ protected $name; + + /** + * @var string + */ protected $email; + + /** + * @var string + */ protected $country; + + /** + * @var bool + */ protected $deleted; + + /** + * @var string|null + */ protected $created_at; + + /** + * @var string|null + */ protected $updated_at; + + /** + * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}|null + */ protected $_options = [ 'datamap' => [], 'dates' => [ @@ -227,13 +258,44 @@ public function testUpdateBatchWithEntity(): void }; $entity2 = new class () extends Entity { + /** + * @var int + */ protected $id; + + /** + * @var string + */ protected $name; + + /** + * @var string + */ protected $email; + + /** + * @var string + */ protected $country; + + /** + * @var bool + */ protected $deleted; + + /** + * @var string|null + */ protected $created_at; + + /** + * @var string|null + */ protected $updated_at; + + /** + * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}|null + */ protected $_options = [ 'datamap' => [], 'dates' => [ @@ -399,13 +461,44 @@ public function testUpdateWithEntityNoAllowedFields(): void $this->createModel(UserModel::class); $entity = new class () extends Entity { + /** + * @var int + */ protected $id; + + /** + * @var string + */ protected $name; + + /** + * @var string + */ protected $email; + + /** + * @var string + */ protected $country; + + /** + * @var bool + */ protected $deleted; + + /** + * @var int|null + */ protected $created_at; + + /** + * @var int|null + */ protected $updated_at; + + /** + * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}|null + */ protected $_options = [ 'datamap' => [], 'dates' => [ diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index b277717823bf..1bc172390faa 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 2116 errors +# total 2092 errors includes: - argument.type.neon diff --git a/utils/phpstan-baseline/missingType.property.neon b/utils/phpstan-baseline/missingType.property.neon index df409e85e4df..66f4f74b5ff3 100644 --- a/utils/phpstan-baseline/missingType.property.neon +++ b/utils/phpstan-baseline/missingType.property.neon @@ -1,4 +1,4 @@ -# total 101 errors +# total 77 errors parameters: ignoreErrors: @@ -386,123 +386,3 @@ parameters: message: '#^Property CodeIgniter\\Model@anonymous/tests/system/Models/SaveModelTest\.php\:290\:\:\$name has no type specified\.$#' count: 1 path: ../../tests/system/Models/SaveModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$_options has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$country has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$created_at has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$deleted has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$email has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$id has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$name has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:210\:\:\$updated_at has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$_options has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$country has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$created_at has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$deleted has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$email has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$id has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$name has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:229\:\:\$updated_at has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$_options has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$country has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$created_at has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$deleted has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$email has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$id has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$name has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/UpdateModelTest\.php\:401\:\:\$updated_at has no type specified\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php From 6bd0c55a02210f4c20cfd1aa36a38c85979b94f5 Mon Sep 17 00:00:00 2001 From: Adi Prasetyo Date: Wed, 4 Mar 2026 13:17:46 +0700 Subject: [PATCH 2/3] use native php type --- tests/system/Models/UpdateModelTest.php | 129 +++++------------------- 1 file changed, 24 insertions(+), 105 deletions(-) diff --git a/tests/system/Models/UpdateModelTest.php b/tests/system/Models/UpdateModelTest.php index 7bc09eec2fc8..58a3adad9a19 100644 --- a/tests/system/Models/UpdateModelTest.php +++ b/tests/system/Models/UpdateModelTest.php @@ -208,43 +208,16 @@ public function testUpdateBatchValidationFail(): void public function testUpdateBatchWithEntity(): void { $entity1 = new class () extends Entity { - /** - * @var int - */ - protected $id; - - /** - * @var string - */ - protected $name; - - /** - * @var string - */ - protected $email; - - /** - * @var string - */ - protected $country; - - /** - * @var bool - */ - protected $deleted; - - /** - * @var string|null - */ - protected $created_at; - - /** - * @var string|null - */ - protected $updated_at; + protected int $id; + protected string $name; + protected string $email; + protected string $country; + protected bool $deleted; + protected int $created_at; + protected int $updated_at; /** - * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}|null + * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}} */ protected $_options = [ 'datamap' => [], @@ -258,43 +231,16 @@ public function testUpdateBatchWithEntity(): void }; $entity2 = new class () extends Entity { - /** - * @var int - */ - protected $id; - - /** - * @var string - */ - protected $name; - - /** - * @var string - */ - protected $email; - - /** - * @var string - */ - protected $country; - - /** - * @var bool - */ - protected $deleted; + protected int $id; + protected string $name; + protected string $email; + protected string $country; + protected bool $deleted; + protected int $created_at; + protected int $updated_at; /** - * @var string|null - */ - protected $created_at; - - /** - * @var string|null - */ - protected $updated_at; - - /** - * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}|null + * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}} */ protected $_options = [ 'datamap' => [], @@ -461,43 +407,16 @@ public function testUpdateWithEntityNoAllowedFields(): void $this->createModel(UserModel::class); $entity = new class () extends Entity { - /** - * @var int - */ - protected $id; - - /** - * @var string - */ - protected $name; - - /** - * @var string - */ - protected $email; - - /** - * @var string - */ - protected $country; - - /** - * @var bool - */ - protected $deleted; - - /** - * @var int|null - */ - protected $created_at; - - /** - * @var int|null - */ - protected $updated_at; + protected int $id; + protected string $name; + protected string $email; + protected string $country; + protected bool $deleted; + protected int $created_at; + protected int $updated_at; /** - * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}|null + * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}} */ protected $_options = [ 'datamap' => [], From 59e8d56d657c6f74680238ba6062b39d8328f97b Mon Sep 17 00:00:00 2001 From: Adi Prasetyo Date: Wed, 4 Mar 2026 17:25:34 +0700 Subject: [PATCH 3/3] use DateTimeInterface type --- tests/system/Models/UpdateModelTest.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/system/Models/UpdateModelTest.php b/tests/system/Models/UpdateModelTest.php index 58a3adad9a19..2e2e61c03e34 100644 --- a/tests/system/Models/UpdateModelTest.php +++ b/tests/system/Models/UpdateModelTest.php @@ -19,6 +19,7 @@ use CodeIgniter\Entity\Entity; use CodeIgniter\Exceptions\InvalidArgumentException; use Config\Database; +use DateTimeInterface; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; use stdClass; @@ -213,8 +214,8 @@ public function testUpdateBatchWithEntity(): void protected string $email; protected string $country; protected bool $deleted; - protected int $created_at; - protected int $updated_at; + protected DateTimeInterface $created_at; + protected DateTimeInterface $updated_at; /** * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}} @@ -236,8 +237,8 @@ public function testUpdateBatchWithEntity(): void protected string $email; protected string $country; protected bool $deleted; - protected int $created_at; - protected int $updated_at; + protected DateTimeInterface $created_at; + protected DateTimeInterface $updated_at; /** * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}} @@ -412,8 +413,8 @@ public function testUpdateWithEntityNoAllowedFields(): void protected string $email; protected string $country; protected bool $deleted; - protected int $created_at; - protected int $updated_at; + protected DateTimeInterface $created_at; + protected DateTimeInterface $updated_at; /** * @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}