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

Cannot call method matches() on Hamcrest\Matcher|null in SeriesMatchingOnce:82

Open pscheit opened this issue 5 months ago • 0 comments

    private function _isMatched($item): bool
    {
        $this->_nextMatchKey = array_shift($this->_keys);
        $nextMatcher = array_shift($this->_elementMatchers);

        if (!$nextMatcher->matches($item)) {
            $this->_describeMismatch($nextMatcher, $item);

            return false;
        }

        return true;
    }

$this->_elementMatchers might have 0 elements when this method is called.

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

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------
  Line   hamcrest/Hamcrest/Arrays/SeriesMatchingOnce.php
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------
  82     Cannot call method matches() on Hamcrest\Matcher|null.
         🪪  method.nonObject
         ✏️  hamcrest/Hamcrest/Arrays/SeriesMatchingOnce.php
  83     Parameter #1 $matcher of method Hamcrest\Arrays\SeriesMatchingOnce::_describeMismatch() expects Hamcrest\Matcher, Hamcrest\Matcher|null given.
         🪪  argument.type
         ✏️  hamcrest/Hamcrest/Arrays/SeriesMatchingOnce.php
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------

pscheit avatar Jul 26 '25 09:07 pscheit