phpinspectionsea icon indicating copy to clipboard operation
phpinspectionsea copied to clipboard

FalsePositive MissUsingForeachInspection

Open puggan opened this issue 2 years ago • 1 comments

Subject Details
Plugin phpInspectionsUltimate-mp (2021.5)
Language level PHP 8.0

Current behaviour

MissUsingForeachInspection asks me to use array_values(), if $hotelCombinationRow->resid was constant, that could have worked, but as that key is dynamic, it's not posible (as far as I know) to replace this foreach with an array_values().

image

$hotelCombinationRows = DB::select($query);
foreach ($hotelCombinationRows as $hotelCombinationRow) {
    $resor[$hotelCombinationRow->resid]->combinatoins[] = $hotelCombinationRow;
}

Expected behaviour

No MissUsingForeachInspection

Environment details

Information from Help - About dialog

PhpStorm 2022.2 EAP Build #PS-222.3153.10, built on June 22, 2022 Licensed to PhpStorm EAP user: Expiration date: July 22, 2022 Runtime version: 17.0.3+7-b469.12 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 11 10.0 GC: G1 Young Generation, G1 Old Generation Memory: 2010M Cores: 8 Registry: run.processes.with.pty=TRUE

Non-Bundled Plugins: com.kalessil.phpStorm.phpInspectionsUltimate-mp (2021.5) de.espend.idea.php.toolbox (6.1.0) de.espend.idea.php.annotation (8.2.1) NEON support (0.5.2) com.jetbrains.plugins.jade (222.3153.10) izhangzhihao.rainbow.brackets (6.25) fr.adrienbrault.idea.symfony2plugin (2022.1.230) ru.adelf.idea.dotenv (2022.2)

puggan avatar Jun 29 '22 15:06 puggan

I just stumbled upon the same FP with this code:

grafik

$result = [];
foreach ($this->elements as $element) {
    $result[$element->getType()][] = $element;
}

I doubt that I can just use array_values() instead, as it's a grouping operation.

Plugin version

com.kalessil.phpStorm.phpInspectionsUltimate-mp (2021.5)

Environment details

PhpStorm 2022.2.1 Build #PS-222.3739.61, built on August 18, 2022 Runtime version: 17.0.3+7-b469.37 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Linux 5.4.0-125-generic GC: G1 Young Generation, G1 Old Generation Memory: 6144M Cores: 8

Current Desktop: ubuntu:GNOME

jdreesen avatar Sep 08 '22 09:09 jdreesen