You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Roles are described as array<string> in symfony/security-core/User/UserInterface.php, whereas they are described as list<string> here src/Security/UserClassBuilder.php.
In itself this is not necessarily problematic, but the function getRoles does not return a list due to array_unique. In fact, array_unique deletes keys on duplicate items, and thus the resulting array is no longer a list which should be an array with sequential keys. (See https://3v4l.org/EMSKK#v8.4.2)
Additional information
There is a mismatch between getRoles() type from symfony/security-core/User/UserInterface.php and the one from src/Security/UserClassBuilder.php. It is thrown by PHPStan.
This error is what made me see the problem.
Method App\Entity\User::getRoles() should return list<string> but returns non-empty-array<string>.
🪪 return.type
💡 non-empty-array<int|string, string> might not be a list.
PHPStan version: 2.1.1
Level max
How to reproduce
In a symfony project, add a User entity using the maker php bin/console make:user
Description
Roles are described as
array<string>
insymfony/security-core/User/UserInterface.php
, whereas they are described aslist<string>
heresrc/Security/UserClassBuilder.php
.In itself this is not necessarily problematic, but the function
getRoles
does not return alist
due toarray_unique
. In fact,array_unique
deletes keys on duplicate items, and thus the resulting array is no longer a list which should be an array with sequential keys. (See https://3v4l.org/EMSKK#v8.4.2)Additional information
There is a mismatch between
getRoles()
type fromsymfony/security-core/User/UserInterface.php
and the one fromsrc/Security/UserClassBuilder.php
. It is thrown by PHPStan.This error is what made me see the problem.
PHPStan version: 2.1.1
Level max
How to reproduce
php bin/console make:user
Solution
See #1646
To fix this, we could change the generated
getRoles
method as:This will reset the keys to be sequential.
Other things that can be done
list<string>
Do not hesitate to give feedback about this, I'm able to update/change if needed :)
The text was updated successfully, but these errors were encountered: