-
Notifications
You must be signed in to change notification settings - Fork 660
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
Psalm doesn't work with const array when key is enum value #9644
Labels
Comments
I found these snippets: https://psalm.dev/r/ed2358aa53<?php
enum TranscodeTypeEnum: string
{
case Case1 = 'case 1';
}
class myClass {}
class TranscodingCreateRequestFactory
{
private const MAP = [
TranscodeTypeEnum::Case1->value => myClass::class,
];
public function createObjectByEnumValue(string $value) : object
{
if (isset(self::MAP[$value])) {
$classname = self::MAP[$value];
return new $classname();
}
throw new RuntimeException('Unknown class for ' . $value);
}
}
https://psalm.dev/r/992a7c1602<?php
enum TranscodeTypeEnum: string
{
case Case1 = 'case 1';
}
class myClass {}
class TranscodingCreateRequestFactory
{
private const MAP = [
'case 1' => myClass::class,
];
public function createObjectByEnumValue(string $value) : object
{
if (isset(self::MAP[$value])) {
$classname = self::MAP[$value];
return new $classname();
}
throw new RuntimeException('Unknown class for ' . $value);
}
}
|
Indeed, Psalm seems to have failed silently here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have const array in class and I use enum's value as key.
Psalm is going crazy with "Constant TranscodingCreateRequestFactory::MAP is not defined"
https://psalm.dev/r/ed2358aa53
But if change array key to simple string - everything works
https://psalm.dev/r/992a7c1602
The text was updated successfully, but these errors were encountered: