Skip to content
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

Use stubfile extension for PasswordUpgraderInterface #335

Conversation

VincentLanglet
Copy link
Contributor

I'm trying to solve #333
@kevinpapst can you try this branch ?

Closes #333

@kevinpapst
Copy link

@VincentLanglet Thank you! Works for SF 4.4. But with SF 6.2 I have other issues now.

Below output is from the SF 4.4 project, Symfony 6.2 follows later:

Below:

$ vendor/bin/phpstan analyse src -c phpstan.neon --level=5
 951/951 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   Security/DoctrineUserProvider.php                                                                                                                                         
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  80     Parameter $user of method App\Security\DoctrineUserProvider::upgradePassword() has invalid type Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface.  
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   Security/KimaiUserProvider.php                                                                                                                                         
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  87     Parameter $user of method App\Security\KimaiUserProvider::upgradePassword() has invalid type Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface.  
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
                                                                                                                        
 [ERROR] Found 2 errors                                                                                                 

Script vendor/bin/phpstan analyse src -c phpstan.neon --level=5 handling the phpstan event returned with error code 1

Composer update:

$ composer update 
Loading composer repositories with package information                                                                                                                                                     Restricting packages listed in "symfony/symfony" to "4.4.*"
Updating dependencies
Lock file operations: 0 installs, 1 update, 0 removals
  - Upgrading phpstan/phpstan-symfony (1.2.23 => dev-PasswordAuthenticatedUserStubFilesExtension d879c1a)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Downloading phpstan/phpstan-symfony (dev-PasswordAuthenticatedUserStubFilesExtension d879c1a)
  - Upgrading phpstan/phpstan-symfony (1.2.23 => dev-PasswordAuthenticatedUserStubFilesExtension d879c1a): Extracting archive
Package sensio/framework-extra-bundle is abandoned, you should avoid using it. Use Symfony instead.
Package symfony/debug is abandoned, you should avoid using it. Use symfony/error-handler instead.
Package symfony/inflector is abandoned, you should avoid using it. Use EnglishInflector from the String component instead.
Package php-cs-fixer/diff is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
139 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

Afterwards:

$ vendor/bin/phpstan analyse src -c phpstan.neon --level=5
 951/951 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
                                                                                                                        
 [OK] No errors                                                                                                         

@VincentLanglet VincentLanglet force-pushed the PasswordAuthenticatedUserStubFilesExtension branch from 20a2e46 to 4243db4 Compare February 19, 2023 17:04
@VincentLanglet
Copy link
Contributor Author

@VincentLanglet Thank you! Works for SF 4.4.

Great

But with SF 6.2 I have other issues now.

Certainly because I used class_exists on an interface so the stub wasn't loaded anymore.
I added a commit to fix it.

@kevinpapst
Copy link

kevinpapst commented Feb 19, 2023

Yep 👍 The lastest commit fixed the SF 6.2 issues. And SF 4.4 still works.

I assume your branch is behind 1.2.23, right?

Because I get PHPDoc tag @extends contains generic type Symfony\Component\Security\Core\Authorization\Voter\Voter<string, App\Entity\Activity> but class Symfony\Component\Security\Core\Authorization\Voter\Voter is not generic. in SF 6.2, which worked in 1.2.23.

@VincentLanglet VincentLanglet force-pushed the PasswordAuthenticatedUserStubFilesExtension branch from 4243db4 to f961a75 Compare February 19, 2023 17:12
@VincentLanglet
Copy link
Contributor Author

Yep 👍 The lastest commit fixed the SF 6.2 issues. And SF 4.4 still works.

Great !

I assume your branch is behind 1.2.23, right?

Because I get PHPDoc tag @extends contains generic type Symfony\Component\Security\Core\Authorization\Voter\Voter<string, App\Entity\Activity> but class Symfony\Component\Security\Core\Authorization\Voter\Voter is not generic. in SF 6.2, which worked in 1.2.23.

Certainly. I rebased my branch ;)

Copy link

@kevinpapst kevinpapst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, now SF 6.2 is green as well. Fixed 👍

Thank you for your quick support, very much appreciated!


public function getFiles(): array
{
if (!interface_exists('Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime concerns are irrelevant for PHPStan, you need to ask ReflectionProvider. If ReflectionProvider cannot be injected, then ask Reflector, as phpstan-doctrine does: https://github.com/phpstan/phpstan-doctrine/blob/1.3.x/src/Stubs/Doctrine/StubFilesExtensionLoader.php

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I understand anything about PHPStan internals, but isn't that the "same" as in : https://github.com/phpstan/phpstan-symfony/blob/1.2.x/src/Symfony/InputBagStubFilesExtension.php#L13 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is reaaaaaally old and should be fixed too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done for both StubFilesExtension.

@VincentLanglet VincentLanglet force-pushed the PasswordAuthenticatedUserStubFilesExtension branch from bda236b to c12047b Compare February 20, 2023 00:14
@VincentLanglet
Copy link
Contributor Author

Friendly ping @ondrejmirtes, is this PR ok to you ?
Thanks.

@ondrejmirtes ondrejmirtes merged commit db81b18 into phpstan:1.2.x Mar 30, 2023
@ondrejmirtes
Copy link
Member

Thank you.

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

Successfully merging this pull request may close these issues.

Generics for PasswordUpgraderInterface fail with SF < 5.3
3 participants