From 2460fafbe8b2f29886177cfca4cbb417e972e58e Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 9 Apr 2024 13:42:00 +0900 Subject: [PATCH 1/2] docs: make PHPDoc types more precise --- phpstan-baseline.php | 5 ----- system/Model.php | 5 +++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index ffe358b48943..bd15482a2db5 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -7431,11 +7431,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Model.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Property CodeIgniter\\\\Model\\:\\:\\$tempData type has no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Model.php', -]; $ignoreErrors[] = [ 'message' => '#^Return type \\(array\\|bool\\|float\\|int\\|object\\|string\\|null\\) of method CodeIgniter\\\\Model\\:\\:__call\\(\\) should be covariant with return type \\(\\$this\\(CodeIgniter\\\\BaseModel\\)\\|null\\) of method CodeIgniter\\\\BaseModel\\:\\:__call\\(\\)$#', 'count' => 1, diff --git a/system/Model.php b/system/Model.php index 61f4350f3117..b3ecfc653943 100644 --- a/system/Model.php +++ b/system/Model.php @@ -40,7 +40,7 @@ * - allow intermingling calls to the builder * - removes the need to use Result object directly in most cases * - * @property BaseConnection $db + * @property-read BaseConnection $db * * @method $this groupBy($by, ?bool $escape = null) * @method $this groupEnd() @@ -123,7 +123,8 @@ class Model extends BaseModel * so that we can capture it (not the builder) * and ensure it gets validated first. * - * @var array + * @var array{escape: array, data: array}|array{} + * @phpstan-var array{escape: array, data: row_array}|array{} */ protected $tempData = []; From edb87e8a45d3a04230502a9cd6baa53e7784559f Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 9 Apr 2024 13:44:03 +0900 Subject: [PATCH 2/2] fix: TypeError when Time is passed to Model --- system/BaseModel.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/system/BaseModel.php b/system/BaseModel.php index 5d08ec59e04c..9b8bb70ed482 100644 --- a/system/BaseModel.php +++ b/system/BaseModel.php @@ -926,6 +926,9 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch $row = (array) $row; } + // Convert any Time instances to appropriate $dateFormat + $row = $this->timeToString($row); + // Validate every row. if (! $this->skipValidation && ! $this->validate($row)) { // Restore $cleanValidationRules @@ -1845,8 +1848,6 @@ protected function transformDataToArray($row, string $type): array $row = $this->converter->toDataSource($row); } elseif ($row instanceof Entity) { $row = $this->converter->extract($row, $onlyChanged); - // Convert any Time instances to appropriate $dateFormat - $row = $this->timeToString($row); } elseif (is_object($row)) { $row = $this->converter->extract($row, $onlyChanged); } @@ -1870,7 +1871,8 @@ protected function transformDataToArray($row, string $type): array throw DataException::forEmptyDataset($type); } - return $row; + // Convert any Time instances to appropriate $dateFormat + return $this->timeToString($row); } /**