Phpinspectionsea: array_merge in loop inspection ignores break/return

Created on 30 Apr 2018  路  2Comments  路  Source: kalessil/phpinspectionsea

I've found the following false positive for this inspection:

$language = 2;
$translations = [
    ['language' => 1, 'desc' => 'translated1']
    ['language' => 2, 'desc' => 'translated2']
];
$data = ['desc' => 'original'];

foreach ($translations as $translation) {
    if ($translation['language'] === $language) {
        $data = array_merge($data, $record);
        break;
    }
}

^ It's just an example, but there are a few cases where this might happen. This might also apply to other statements like return.

Docs: https://github.com/kalessil/phpinspectionsea/blob/master/docs/performance.md#slow-array-function-used-in-loop

bug / false-positive fixed

Most helpful comment

Fixed

All 2 comments

Thank you for reporting @uuf6429, I'll take care of the issue.

Fixed

Was this page helpful?
0 / 5 - 0 ratings