Skip to content

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

@Xbirdfr

Description

@Xbirdfr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions