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

Author: pscheitCreated Jul 26, 2025Updated Jul 26, 2025
php
    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
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------