Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum Interfaces cannot be found #11030

Open
cseufert opened this issue Jun 28, 2024 · 3 comments
Open

Enum Interfaces cannot be found #11030

cseufert opened this issue Jun 28, 2024 · 3 comments

Comments

@cseufert
Copy link

cseufert commented Jun 28, 2024

Here is an example of trying to unmarshal a value based on reflecting the type expected $class. Psalm complains that the InBackedNum interface cannot be found. Does this need to be stubbed?

I have had a read of the previous enum issues, and there's no mention of this type of use-case.

<?php
/** @var class-string $class */
$class = 'test';

if (is_a($class, \IntBackedEnum::class, true)) {
	return $class::from((int) $v->toString());
}

https://psalm.dev/r/8c09bf5115

Copy link

psalm-github-bot bot commented Jun 28, 2024

I found these snippets:

https://psalm.dev/r/8c09bf5115
<?php
/** @var class-string $class */
$class = 'test';

if (is_a($class, \IntBackedEnum::class, true)) {
	return $class::from((int) $v->toString());
}
Psalm output (using commit 16b24bd):

ERROR: UndefinedClass - 5:18 - Class, interface or enum named IntBackedEnum does not exist

INFO: MixedArgument - 5:18 - Argument 2 of is_a cannot be mixed, expecting class-string

ERROR: UndefinedClass - 6:9 - Class, interface or enum named IntBackedEnum does not exist

ERROR: UndefinedGlobalVariable - 6:28 - Cannot find referenced variable $v in global scope

INFO: MixedMethodCall - 6:32 - Cannot determine the type of $v when calling method toString

@cseufert
Copy link
Author

You also cant type-hint via a class string \IntBackedEnum either.

https://psalm.dev/r/d0694ad217

Copy link

I found these snippets:

https://psalm.dev/r/d0694ad217
<?php
/** @var class-string<\IntBackedEnum> $class */
$enum = 'MyEnum';

$enum::cases();
Psalm output (using commit 16b24bd):

ERROR: UndefinedDocblockClass - 3:1 - Docblock-defined class, interface or enum named IntBackedEnum does not exist

ERROR: InvalidStringClass - 5:1 - String cannot be used as a class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant