Skip to content

Commit 78c9326

Browse files
committed
refactor: replace method_exists($object, 'toRawArray') with $object instanceof Entity
1 parent c307e5e commit 78c9326

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

system/BaseModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use CodeIgniter\Database\Exceptions\DatabaseException;
1818
use CodeIgniter\Database\Exceptions\DataException;
1919
use CodeIgniter\Database\Query;
20+
use CodeIgniter\Entity\Entity;
2021
use CodeIgniter\Exceptions\ModelException;
2122
use CodeIgniter\I18n\Time;
2223
use CodeIgniter\Pager\Pager;
@@ -1711,8 +1712,7 @@ protected function timeToString(array $properties): array
17111712
*/
17121713
protected function objectToRawArray($object, bool $onlyChanged = true, bool $recursive = false): array
17131714
{
1714-
// Entity::toRawArray() returns array.
1715-
if (method_exists($object, 'toRawArray')) {
1715+
if ($object instanceof Entity) {
17161716
$properties = $object->toRawArray($onlyChanged, $recursive);
17171717
} else {
17181718
$mirror = new ReflectionClass($object);

system/Model.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,7 @@ protected function objectToRawArray($object, bool $onlyChanged = true, bool $rec
816816

817817
// Always grab the primary key otherwise updates will fail.
818818
if (
819-
// @TODO Should use `$data instanceof Entity`.
820-
method_exists($object, 'toRawArray')
819+
$object instanceof Entity
821820
&& (
822821
! empty($properties)
823822
&& ! empty($this->primaryKey)

0 commit comments

Comments
 (0)