phpinspectionsea
phpinspectionsea copied to clipboard
Properties shouldn't trigger "Statement could be decoupled from foreach"
| Subject | Details |
|---|---|
| Plugin | Php Inspections (EA Ultimate) 2021.5 |
| Language level | PHP 8.1 |
Current behaviour
Calling methods on properties inside loops triggers "Statement could be decoupled from foreach", e.g.
foreach($ids as $id) {
$object = $this->entityManager->getRepository(Entity::Class)->find($id);
$object->setSomething(123);
$this->entityManager->flush();
$this->entityManager->clear();
}
will mark the two calls for ->flush() and ->clear() as possibly decoupled.
Expected behaviour
Properties shouldn't be considered part of the loop.
Sure, I could suppress it each time, but it's cumbersome. I'd be fine with them being reported by default but having an option for the inspection to ignore properties of the current object.
Environment details
PhpStorm 2022.3.1 Build #PS-223.8214.64, built on December 22, 2022 Runtime version: 17.0.5+1-b653.23 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Linux 5.4.0-137-generic GC: G1 Young Generation, G1 Old Generation Memory: 4096M