Skip to content

Commit

Permalink
Merge pull request #7986 from kenjis/fix-Model-objectToRawArray-retur…
Browse files Browse the repository at this point in the history
…n-type

fix: incorrect return type for Model::objectToRawArray()
  • Loading branch information
kenjis authored Sep 30, 2023
2 parents 29d4795 + 952aabd commit d40c071
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions user_guide_src/source/changelogs/v4.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,20 @@ Interface Changes
- **Logger:** The `psr/log <https://packagist.org/packages/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
Expand Down
9 changes: 8 additions & 1 deletion user_guide_src/source/installation/upgrade_450.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <v450-method-signature-changes>`
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 <v450-removed-deprecated-items>` for details.

Breaking Enhancements
*********************
Expand Down

0 comments on commit d40c071

Please sign in to comment.