Skip to content

Commit 8dccc27

Browse files
authored
Merge pull request #8738 from kenjis/fix-Model-handling-Time
fix: TypeError when Time is passed to Model
2 parents 0d1c6b9 + edb87e8 commit 8dccc27

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

phpstan-baseline.php

-5
Original file line numberDiff line numberDiff line change
@@ -7431,11 +7431,6 @@
74317431
'count' => 1,
74327432
'path' => __DIR__ . '/system/Model.php',
74337433
];
7434-
$ignoreErrors[] = [
7435-
'message' => '#^Property CodeIgniter\\\\Model\\:\\:\\$tempData type has no value type specified in iterable type array\\.$#',
7436-
'count' => 1,
7437-
'path' => __DIR__ . '/system/Model.php',
7438-
];
74397434
$ignoreErrors[] = [
74407435
'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\\(\\)$#',
74417436
'count' => 1,

system/BaseModel.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,9 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
926926
$row = (array) $row;
927927
}
928928

929+
// Convert any Time instances to appropriate $dateFormat
930+
$row = $this->timeToString($row);
931+
929932
// Validate every row.
930933
if (! $this->skipValidation && ! $this->validate($row)) {
931934
// Restore $cleanValidationRules
@@ -1845,8 +1848,6 @@ protected function transformDataToArray($row, string $type): array
18451848
$row = $this->converter->toDataSource($row);
18461849
} elseif ($row instanceof Entity) {
18471850
$row = $this->converter->extract($row, $onlyChanged);
1848-
// Convert any Time instances to appropriate $dateFormat
1849-
$row = $this->timeToString($row);
18501851
} elseif (is_object($row)) {
18511852
$row = $this->converter->extract($row, $onlyChanged);
18521853
}
@@ -1870,7 +1871,8 @@ protected function transformDataToArray($row, string $type): array
18701871
throw DataException::forEmptyDataset($type);
18711872
}
18721873

1873-
return $row;
1874+
// Convert any Time instances to appropriate $dateFormat
1875+
return $this->timeToString($row);
18741876
}
18751877

18761878
/**

system/Model.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* - allow intermingling calls to the builder
4141
* - removes the need to use Result object directly in most cases
4242
*
43-
* @property BaseConnection $db
43+
* @property-read BaseConnection $db
4444
*
4545
* @method $this groupBy($by, ?bool $escape = null)
4646
* @method $this groupEnd()
@@ -123,7 +123,8 @@ class Model extends BaseModel
123123
* so that we can capture it (not the builder)
124124
* and ensure it gets validated first.
125125
*
126-
* @var array
126+
* @var array{escape: array, data: array}|array{}
127+
* @phpstan-var array{escape: array<int|string, bool|null>, data: row_array}|array{}
127128
*/
128129
protected $tempData = [];
129130

0 commit comments

Comments
 (0)