diff --git a/phpstan-baseline.php b/phpstan-baseline.php index a08185d5f2b0..542ca2dbf8c2 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -71,11 +71,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/BaseModel.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, array\\|null given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/BaseModel.php', -]; $ignoreErrors[] = [ 'message' => '#^Only booleans are allowed in an if condition, int given\\.$#', 'count' => 1, diff --git a/system/BaseModel.php b/system/BaseModel.php index 0cf63ac9f3ec..63a87e587828 100644 --- a/system/BaseModel.php +++ b/system/BaseModel.php @@ -1657,7 +1657,7 @@ protected function objectToArray($data, bool $onlyChanged = true, bool $recursiv $properties = $this->objectToRawArray($data, $onlyChanged, $recursive); // Convert any Time instances to appropriate $dateFormat - if ($properties) { + if ($properties !== []) { $properties = array_map(function ($value) { if ($value instanceof Time) { return $this->timeToDate($value); @@ -1678,12 +1678,13 @@ protected function objectToArray($data, bool $onlyChanged = true, bool $recursiv * @param bool $onlyChanged Only Changed Property * @param bool $recursive If true, inner entities will be casted as array as well * - * @return array|null Array + * @return array Array with raw values. * * @throws ReflectionException */ - protected function objectToRawArray($data, bool $onlyChanged = true, bool $recursive = false): ?array + protected function objectToRawArray($data, bool $onlyChanged = true, bool $recursive = false): array { + // @TODO Should define Interface or Class. Entity has toRawArray() now. if (method_exists($data, 'toRawArray')) { $properties = $data->toRawArray($onlyChanged, $recursive); } else { diff --git a/system/Model.php b/system/Model.php index e53c0aae4bd1..b8c4de4470a2 100644 --- a/system/Model.php +++ b/system/Model.php @@ -783,11 +783,11 @@ public function update($id = null, $data = null): bool * @param object|string $data * @param bool $recursive If true, inner entities will be cast as array as well * - * @return array|null Array + * @return array Array with raw values. * * @throws ReflectionException */ - protected function objectToRawArray($data, bool $onlyChanged = true, bool $recursive = false): ?array + protected function objectToRawArray($data, bool $onlyChanged = true, bool $recursive = false): array { $properties = parent::objectToRawArray($data, $onlyChanged); diff --git a/user_guide_src/source/changelogs/v4.5.0.rst b/user_guide_src/source/changelogs/v4.5.0.rst index 8bff44c26ab0..49b2fd6f4ac5 100644 --- a/user_guide_src/source/changelogs/v4.5.0.rst +++ b/user_guide_src/source/changelogs/v4.5.0.rst @@ -35,9 +35,20 @@ Interface Changes - **Logger:** The `psr/log `_ package has been upgraded to v2.0.0. +.. _v450-method-signature-changes: + Method Signature Changes ======================== +Return Type Changes +------------------- + +- **Model:** The return type of the ``objectToRawArray()`` method in the ``Model`` + and ``BaseModel`` classes has been changed from ``?array`` to ``array``. + +Others +------ + - **Logger:** The method signatures of the methods in ``CodeIgniter\Log\Logger`` that implements the PSR-3 interface have been fixed. The ``bool`` return types are changed to ``void``. The ``$message`` parameters now have diff --git a/user_guide_src/source/installation/upgrade_450.rst b/user_guide_src/source/installation/upgrade_450.rst index a9925320bf2d..74fcf24a9e0e 100644 --- a/user_guide_src/source/installation/upgrade_450.rst +++ b/user_guide_src/source/installation/upgrade_450.rst @@ -18,11 +18,18 @@ Mandatory File Changes Breaking Changes **************** +Method Signature Changes +======================== + +Some method signature changes have been made. Classes that extend them should +update their APIs to reflect the changes. See :ref:`ChangeLog ` +for details. + Removed Deprecated Items ======================== Some deprecated items have been removed. If you extend these classes and are -using them, upgrade your code. See :ref:`v450-removed-deprecated-items` for details. +using them, upgrade your code. See :ref:`ChangeLog ` for details. Breaking Enhancements *********************