I have a value storing the following property
/**
* @var \Smpl\Utils\Contracts\Supplier<\Smpl\Collections\Contracts\Collection<array-key, E>>|iterable<E>
* @noinspection PhpDocFieldTypeMismatchInspection
*/
private Supplier|iterable $elementSupplier;
Then later on I have the following method.
/**
* @return iterable<E>
*
* @throws \Smpl\Collections\Exceptions\InvalidArgumentException
*/
protected function getElements(): iterable
{
$elements = $this->elementSupplier;
if ($elements instanceof Supplier) {
$elements = $elements->get();
}
if (! is_iterable($elements)) {
throw InvalidArgumentException::invalidElementSupplier(static::class);
}
return $elements;
}
The $elements = $elements->get() line is causing the following error, even though it's wrapped in an instanceof check.
ERROR: PossiblyInvalidMethodCall - src/Concerns/SuppliesElementsForOperation.php:40:36 - Cannot call method on possible iterable<mixed, E:Smpl\Collections\Operations\DifferenceOperation as mixed> variable $elements (see https://psalm.dev/113)
$elements = $elements->get();
I have a value storing the following property
Then later on I have the following method.
The
$elements = $elements->get()line is causing the following error, even though it's wrapped in aninstanceofcheck.