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

chore: add PHPStan #13

Merged
merged 5 commits into from
Oct 21, 2023
Merged

chore: add PHPStan #13

merged 5 commits into from
Oct 21, 2023

Conversation

rafaucau
Copy link
Contributor

I tried to find the cause of the login problems (https://discuss.flarum.org/d/33339-2fa-two-factor-authentication-with-totp/37), but unfortunately lack of time.

I added PHPStan to make it easier to catch problems. I fixed a few, but there are still some left:

 ------ ----------------------------------------------------------------------------------------------------- 
  Line   src\Api\Controller\DisableTwoFactorController.php                                                    
 ------ ----------------------------------------------------------------------------------------------------- 
  54     Method IanM\TwoFactor\Api\Controller\DisableTwoFactorController::handle() should return              
         Psr\Http\Message\ResponseInterface but returns Illuminate\Database\Eloquent\ModelNotFoundException.  
 ------ ----------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------ 
  Line   src\Api\Controller\ShowQrCodeController.php                                                                 
 ------ ------------------------------------------------------------------------------------------------------------ 
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                                    
  47     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                                    
  52     Method IanM\TwoFactor\Contracts\TotpInterface::getProvisioningUri() invoked with 2 parameters, 1 required.  
 ------ ------------------------------------------------------------------------------------------------------------ 

 ------ ------------------------------------------------------------------------------ 
  Line   src\Api\Serializer\TwoFactorSerializer.php                                    
 ------ ------------------------------------------------------------------------------ 
  34     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$created_at.  
  35     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$updated_at.  
 ------ ------------------------------------------------------------------------------ 

 ------ -------------------------------------------------------------------------------- 
  Line   src\Services\BackupCodeGenerator.php                                            
 ------ -------------------------------------------------------------------------------- 
  53     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$backup_codes.  
  59     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$backup_codes.  
  80     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$backup_codes.  
 ------ -------------------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------------------------------------------- 
  Line   src\Services\OtpWrapper.php                                                                              
 ------ --------------------------------------------------------------------------------------------------------- 
  31     Parameter #1 $label of method OTPHP\OTP::setLabel() expects non-empty-string, string given.              
  52     Parameter #1 $secret of method OTPHP\TOTP::createFromSecret() expects non-empty-string, string given.    
  53     Parameter $otp of method OTPHP\TOTP::verify() expects non-empty-string, string given.                    
  64     Parameter #1 $secret of static method OTPHP\TOTP::create() expects non-empty-string|null, string given.  
 ------ --------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class IanM\TwoFactor\Api\AddCurrentUserAttributes)  
 ------ -------------------------------------------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Api\AddCurrentUserAttributes::$totp.                           
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                                      
 ------ -------------------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class IanM\TwoFactor\Api\AddUserAttributes)  
 ------ ------------------------------------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Api\AddUserAttributes::$totp.                           
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                               
 ------ ------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class           
         IanM\TwoFactor\Api\Controller\CreateTwoFactorTokenController)             
 ------ -------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.  
 ------ -------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class                                   
         IanM\TwoFactor\Api\Controller\DisableTwoFactorController)                                         
 ------ -------------------------------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Api\Controller\DisableTwoFactorController::$totp.  
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                          
 ------ -------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class                                         
         IanM\TwoFactor\Api\Controller\TwoFactorResetPasswordController)                                         
 ------ -------------------------------------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Api\Controller\TwoFactorResetPasswordController::$totp.  
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                                
 ------ -------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class           
         IanM\TwoFactor\Api\Controller\TwoFactorSavePasswordController)            
 ------ -------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.  
 ------ -------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class           
         IanM\TwoFactor\Api\Controller\VerifyTwoFactorController)                  
 ------ -------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.  
 ------ -------------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class IanM\TwoFactor\OAuth\TwoFactorOAuthCheck)  
 ------ ----------------------------------------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                                   
 ------ ----------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class IanM\TwoFactor\Services\TwoFactorRestrictor)  
 ------ -------------------------------------------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                                      
  46     Access to an undefined property IanM\TwoFactor\Services\TwoFactorRestrictor::$totp.                           
 ------ -------------------------------------------------------------------------------------------------------------- 

 [ERROR] Found 27 errors   ------ ----------------------------------------------------------------------------------------------------- 
  Line   src\Api\Controller\DisableTwoFactorController.php                                                    
 ------ ----------------------------------------------------------------------------------------------------- 
  54     Method IanM\TwoFactor\Api\Controller\DisableTwoFactorController::handle() should return              
         Psr\Http\Message\ResponseInterface but returns Illuminate\Database\Eloquent\ModelNotFoundException.  
 ------ ----------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------ 
  Line   src\Api\Controller\ShowQrCodeController.php                                                                 
 ------ ------------------------------------------------------------------------------------------------------------ 
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                                    
  47     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                                    
  52     Method IanM\TwoFactor\Contracts\TotpInterface::getProvisioningUri() invoked with 2 parameters, 1 required.  
 ------ ------------------------------------------------------------------------------------------------------------ 

 ------ ------------------------------------------------------------------------------ 
  Line   src\Api\Serializer\TwoFactorSerializer.php                                    
 ------ ------------------------------------------------------------------------------ 
  34     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$created_at.  
  35     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$updated_at.  
 ------ ------------------------------------------------------------------------------ 

 ------ -------------------------------------------------------------------------------- 
  Line   src\Services\BackupCodeGenerator.php                                            
 ------ -------------------------------------------------------------------------------- 
  53     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$backup_codes.  
  59     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$backup_codes.  
  80     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$backup_codes.  
 ------ -------------------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------------------------------------------- 
  Line   src\Services\OtpWrapper.php                                                                              
 ------ --------------------------------------------------------------------------------------------------------- 
  31     Parameter #1 $label of method OTPHP\OTP::setLabel() expects non-empty-string, string given.              
  52     Parameter #1 $secret of method OTPHP\TOTP::createFromSecret() expects non-empty-string, string given.    
  53     Parameter $otp of method OTPHP\TOTP::verify() expects non-empty-string, string given.                    
  64     Parameter #1 $secret of static method OTPHP\TOTP::create() expects non-empty-string|null, string given.  
 ------ --------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class IanM\TwoFactor\Api\AddCurrentUserAttributes)  
 ------ -------------------------------------------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Api\AddCurrentUserAttributes::$totp.                           
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                                      
 ------ -------------------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class IanM\TwoFactor\Api\AddUserAttributes)  
 ------ ------------------------------------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Api\AddUserAttributes::$totp.                           
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                               
 ------ ------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class           
         IanM\TwoFactor\Api\Controller\CreateTwoFactorTokenController)             
 ------ -------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.  
 ------ -------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class                                   
         IanM\TwoFactor\Api\Controller\DisableTwoFactorController)                                         
 ------ -------------------------------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Api\Controller\DisableTwoFactorController::$totp.  
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                          
 ------ -------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class                                         
         IanM\TwoFactor\Api\Controller\TwoFactorResetPasswordController)                                         
 ------ -------------------------------------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Api\Controller\TwoFactorResetPasswordController::$totp.  
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                                
 ------ -------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class           
         IanM\TwoFactor\Api\Controller\TwoFactorSavePasswordController)            
 ------ -------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.  
 ------ -------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class           
         IanM\TwoFactor\Api\Controller\VerifyTwoFactorController)                  
 ------ -------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.  
 ------ -------------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class IanM\TwoFactor\OAuth\TwoFactorOAuthCheck)  
 ------ ----------------------------------------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                                   
 ------ ----------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------------- 
  Line   src\Trait\TwoFactorAuthenticationTrait.php (in context of class IanM\TwoFactor\Services\TwoFactorRestrictor)  
 ------ -------------------------------------------------------------------------------------------------------------- 
  46     Access to an undefined property IanM\TwoFactor\Model\TwoFactor::$secret.                                      
  46     Access to an undefined property IanM\TwoFactor\Services\TwoFactorRestrictor::$totp.                           
 ------ -------------------------------------------------------------------------------------------------------------- 

 [ERROR] Found 27 errors  

Copy link
Owner

@imorland imorland left a comment

Choose a reason for hiding this comment

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

Thanks for this! I have a suspicion for the login problem, I'll work on that as soon as I can

@imorland imorland merged commit 764ab76 into imorland:master Oct 21, 2023
2 checks passed
@rafaucau rafaucau deleted the chore/add-phpstan branch October 21, 2023 17:31
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.

2 participants