-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Pslam errors with FlagBag #192
Comments
does adding: * @template T of \BackedEnum to the |
Yes, with this change, Pslam does not more complain about invalid argument. |
PR welcomed then :) |
Fixed in #193 |
Hello, I open this error again because Pslam complains about the following code: private function getDefaultPermissions(): FlagBag
{
return FlagBag::from(Permissions::Execute , Permissions::Write, Permissions::Read);
}
I have modified the /**
* @template E of \BackedEnum
* @param class-string<E>|E $enumOrType
* @param E ...$flags
* @return FlagBag<E>
*/
public static function from(string|\BackedEnum $enumOrType, \BackedEnum ...$flags): static
{
//...
} And it work without error. |
It seems the suggested code triggers an issue with PHPStan : ------ -----------------------------------------------------------------------------------------------------------------------------
Line FlagBag.php
------ -----------------------------------------------------------------------------------------------------------------------------
90 PHPDoc tag @return with type Elao\Enum\FlagBag<E of BackedEnum> is incompatible with native type static(Elao\Enum\FlagBag<T
of BackedEnum>).
------ ----------------------------------------------------------------------------------------------------------------------------- |
OK. I tested with a new specific PHPStan annotation and it's work for both (PHPStan and Pslam): /**
* @param class-string<T>|T $enumOrType
*
* @phpstan-return FlagBag<T>
*
* @psalm-template E of \BackedEnum
* @psalm-param E ...$flags
* @psalm-return FlagBag<E>
*/
public static function from(string|\BackedEnum $enumOrType, \BackedEnum ...$flags): static
{
// ...
} |
Any news about this ? Thanks |
Does /**
* @param class-string<T>|T $enumOrType
* @param T ...$flags
*
* @return FlagBag<T>
*/
public static function from(string|\BackedEnum $enumOrType, \BackedEnum ...$flags): static
{
// ...
} work? I don't get why we should add another generic type |
It is not working for me. I tried with the following annotations (using a new named template): /**
* @template E of \BackedEnum
*
* @param class-string<E> $enumType
*
* @return FlagBag<E>
*/
public static function fromAll(string $enumType): FlagBag
{
// ...
} And it's working! I do the same for the /**
* @template E of \BackedEnum
*
* @param class-string<E>|E $enumOrType
* @param E ...$flags
*
* @return FlagBag<E>
*/
public static function from(string|\BackedEnum $enumOrType, \BackedEnum ...$flags): static
{
// ...
} |
Great news! Would you be up to provide the PR? |
I have some errors when I use the
FlagBag
class and test within Psalm.Example:
I then use this enumeration within FlagBag:
Pslam report this error:
We have annoted the Permissions class ?
The text was updated successfully, but these errors were encountered: