flow icon indicating copy to clipboard operation
flow copied to clipboard

Static analysis - avoid unnecessary counts

Open norberttech opened this issue 2 years ago • 0 comments

It would be nice to have static analysis detect following scenario as invalid:


$array = [];

if (\count($array)) {
   foreach ($array as $element) {
        // some logic
   }
}

Since the array is not nullable foreach would do nothing, so count is unnecessary.

#Ref: https://github.com/flow-php/flow/pull/712#discussion_r1380182613

norberttech avatar Nov 02 '23 17:11 norberttech