Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TypeError when Time is passed to Model #8738

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<int|string, bool|null>, data: row_array}|array{}
*/
protected $tempData = [];

Expand Down
Loading