The expression $this->array of type array<integer,object<Ubi...ash\FlashMessage>>|null is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
$collection=json_decode($data,true);if(!is_array($collection)){thrownew\RuntimeException('$collection must be an array.');}foreach($collectionas$item){/** ... */}
If you are sure that the expression is traversable, you might want to add a
doc comment cast to improve IDE auto-completion and static analysis:
Are you sure the assignment to $this->array is correct as \Ubiquity\utils\SessionU..._BAG_KEY, $this->array) (which targets Ubiquity\utils\SessionUtils::set()) seems to always return null.
This check looks for function or method calls that always return null and whose
return value is assigned to a variable.
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.