Skip to content

[sym7] Make:user not compatible with phpstan #1404

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

Closed
Xbirdfr opened this issue Dec 6, 2023 · 4 comments
Closed

[sym7] Make:user not compatible with phpstan #1404

Xbirdfr opened this issue Dec 6, 2023 · 4 comments

Comments

@Xbirdfr
Copy link
Contributor

Xbirdfr commented Dec 6, 2023

Hi !

when using the maker bundle to create user auth system, phpstan seem not very happy with what you get

To reproduce, do this : (I use the symfony cli on version 5.7.4)

symfony new --webapp .
symfony console make:user

with all parameters by default

The name of the security user class (e.g. User) [User]:
 > 

 Do you want to store user data in the database (via Doctrine)? (yes/no) [yes]:
 > 

 Enter a property name that will be the unique "display" name for the user (e.g. email, username, uuid) [email]:
 > 

 Will this app need to hash/check user passwords? Choose No if passwords are not needed or will be checked/hashed by some other system (e.g. a single sign-on server).

 Does this app need to hash/check user passwords? (yes/no) [yes]:
 >

then add phpstan

composer require --dev phpstan/phpstan

and answer yes when the recipe ask execution

recipe : https://github.com/symfony/recipes-contrib/tree/main/phpstan/phpstan/1.0

this add the phpstan.dist.neon file, with "level: 6" check

finally, execute phpstan :

phpstan analyse ./src

and you got errors :

Note: Using configuration file E:\_workspace\symfony7-test\phpstan.dist.neon.
 3/3 [============================] 100%

 ------ --------------------------------------------------------------------------------------
  Line   Entity\User.php

 ------ --------------------------------------------------------------------------------------
  :22    Property App\Entity\User::$roles type has no value type specified in iterable    

         type array.

         💡 See:

            https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  :69    Method App\Entity\User::setRoles() has parameter $roles with no value type       

         specified in iterable type array.

         💡 See:

            https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
 ------ --------------------------------------------------------------------------------------

 ------ --------------------------------------------------------------------------------- 
  Line   Repository\UserRepository.php
 ------ --------------------------------------------------------------------------------- 
  :21    PHPDoc tag @implements contains generic type
         Symfony\Component\Security\Core\User\PasswordUpgraderInterface<App\Entity\User>  
         but interface Symfony\Component\Security\Core\User\PasswordUpgraderInterface is  
         not generic.
 ------ --------------------------------------------------------------------------------- 

                                                                                          
 [ERROR] Found 3 errors
@Xbirdfr
Copy link
Contributor Author

Xbirdfr commented Dec 6, 2023

I think I can fix Entity\User.php with :

line 22 :

/**
     * User's roles
     *
     * @var array<string>
     */
    #[ORM\Column]
    private array $roles = [];

and line 74 :

**
     * Add user's role(s)
     *
     * @param array<string> $roles
     * @return static
     */
    public function setRoles(array $roles): static
    {
        $this->roles = $roles;

        return $this;
    }

but I don't know if this is a good way to fix this, also I don't know how to fix Repository\UserRepository.php

@Xbirdfr
Copy link
Contributor Author

Xbirdfr commented Dec 9, 2023

PHPDoc tag @implements contains generic type
         Symfony\Component\Security\Core\User\PasswordUpgraderInterface<App\Entity\User>  
         but interface Symfony\Component\Security\Core\User\PasswordUpgraderInterface is  
         not generic.

seem related to symfony/symfony@d473b90

@Xbirdfr
Copy link
Contributor Author

Xbirdfr commented Dec 9, 2023

PHPDoc tag @implements contains generic type
         Symfony\Component\Security\Core\User\PasswordUpgraderInterface<App\Entity\User>  
         but interface Symfony\Component\Security\Core\User\PasswordUpgraderInterface is  
         not generic.

seem fixed by this PR https://github.com/symfony/maker-bundle/pull/1402/files

@maelanleborgne
Copy link
Contributor

Can be closed now that #1402 and #1411 have been merged

@Xbirdfr Xbirdfr closed this as completed Feb 25, 2024
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

2 participants