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: incorrect return type for Model::objectToRawArray() #7986

Merged
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 @@ -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.
*
Comment on lines +1681 to 1682
Copy link
Contributor

@mostafakhudair mostafakhudair Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return array Array with raw values.
*

I think the description here is not necessary, since the method has a specific return type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent of the comment is to indicate that the values are raw values.
However, I doubt that most people correctly understand what raw values are.

* @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.
*
Comment on lines +786 to 787
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return array Array with raw values.
*

Also here.

* @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