Skip to content

Non-existing class crashes in ForeachAnalyzer #5983

@ohader

Description

@ohader

https://psalm.dev/r/78e3962d20

Real world example: https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/Cache/Traits/RedisTrait.php#L548-L553

Uncaught InvalidArgumentException: Could not get class storage for predis\connection\aggregate\clusterinterface in /vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php:43

Triggered by:

|| $codebase->classImplements(
$iterator_atomic_type->value,
'Traversable'
) ||
(
$codebase->interfaceExists($iterator_atomic_type->value)
&& $codebase->interfaceExtends(
$iterator_atomic_type->value,
'Traversable'
)
))

Potential fix (wrap in try/catch, return false in case subject class does not exist):

$class_storage = $this->classlike_storage_provider->get($fq_class_name);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions