The expression $requiredFields of type array|integer|double|string|boolean 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:
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.