Skip to content
Merged
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: 3 additions & 2 deletions system/Helpers/array_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ function dot_array_search(string $index, array $array)
function _array_search_dot(array $indexes, array $array)
{
// Grab the current index
$currentIndex = $indexes ? array_shift($indexes) : null;
$currentIndex = $indexes ? array_shift($indexes) : null;
$intCurrentIndex = (int) $currentIndex;

if ((empty($currentIndex) && (int) $currentIndex !== 0) || (! isset($array[$currentIndex]) && $currentIndex !== '*')) {
if (empty($currentIndex) && $intCurrentIndex !== 0 || (! isset($array[$currentIndex]) && $currentIndex !== '*')) {
Copy link
Copy Markdown
Member

@kenjis kenjis Oct 6, 2022

Choose a reason for hiding this comment

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

If $currentIndex is null, empty($currentIndex) is true and $intCurrentIndex !== 0 is false.
If $currentIndex is not null, empty($currentIndex) is false and $intCurrentIndex !== 0 is true.
So the left side is still always false.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this seem better?

        // Grab the current index
        $currentIndex = $indexes ? array_shift($indexes) : null;

        if ($currentIndex === null || (! isset($array[$currentIndex]) && $currentIndex !== '*')) {
            return null;
        }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm sorry, I didn't realize it changed between my review and the merge. This was originally just removing the extraneous part of the conditional.

Yours is better but this still has a lot of cognitive complexity and anyone working on it in the future will need to spend some time figuring it out. Maybe we should break it up into separate return statements? Or extract the second half of the conditional as a variable with a helpful name?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Okay, I will fix this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I sent a PR #6645

return null;
}

Expand Down