hamcrest-php icon indicating copy to clipboard operation
hamcrest-php copied to clipboard

Argument of an invalid type list<string>|false supplied for foreach, only iterables are supported. in IsEqualIgnoringWhiteSpace:66

Open pscheit opened this issue 5 months ago • 0 comments

    private function _stripSpace(string $string): string
    {
        $parts = preg_split("/[\r\n\t ]+/", $string);
        foreach ($parts as $i => $part) {
            $parts[$i] = trim($part, " \r\n\t");
        }

        return trim(implode(' ', $parts), " \r\n\t");
    }

This error is detected by phpstan and was written to the baseline in #88

 ------ ----------------------------------------------------------------------------------------------------
  Line   hamcrest/Hamcrest/Text/IsEqualIgnoringWhiteSpace.php
 ------ ----------------------------------------------------------------------------------------------------
  66     Argument of an invalid type list<string>|false supplied for foreach, only iterables are supported.
         🪪  foreach.nonIterable
         ✏️  hamcrest/Hamcrest/Text/IsEqualIgnoringWhiteSpace.php
  67     Cannot access offset int<0, max> on non-empty-array<int<0, max>, string>|false.
         🪪  offsetAccess.nonOffsetAccessible
         ✏️  hamcrest/Hamcrest/Text/IsEqualIgnoringWhiteSpace.php
 ------ ----------------------------------------------------------------------------------------------------

pscheit avatar Jul 26 '25 09:07 pscheit