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

docs: add annotation for phpstan #19

Closed
wants to merge 13 commits into from
Closed

Conversation

datamweb
Copy link
Owner

@datamweb datamweb commented Nov 10, 2022

I try in this PR, To fix the errors identified by phpstan at level 9.

This is my first experience, anyone please help.

πŸ€¦β€β™‚οΈ all errors : 154

@datamweb
Copy link
Owner Author

datamweb commented Nov 10, 2022

Before

 ------ ---------------------------------------------------------------------------------------------------------------
  Line   ShieldOAuthConfig.php
 ------ ---------------------------------------------------------------------------------------------------------------
  20     Property Datamweb\ShieldOAuth\Config\ShieldOAuthConfig::$oauthConfigs type has no value type specified in
         iterable type array.
         πŸ’‘ See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  56     Property Datamweb\ShieldOAuth\Config\ShieldOAuthConfig::$usersColumnsName type has no value type specified in
         iterable type array.
         πŸ’‘ See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
 ------ --------------------------------------------------------------------------------------------------------------- 

After

 1/1 [============================] 100%

 [OK] No errors

@datamweb datamweb mentioned this pull request Nov 10, 2022
3 tasks
@datamweb
Copy link
Owner Author

datamweb commented Nov 10, 2022

Before:

> phpstan analyze src/Config/Registrar.php

 1/1 [============================] 100%

 ------ ----------------------------------------------------------------------------------------------------------------------
  Line   Registrar.php
 ------ ----------------------------------------------------------------------------------------------------------------------
  30     Method Datamweb\ShieldOAuth\Config\Registrar::View() return type has no value type specified in iterable type array.
         πŸ’‘ See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
 ------ ----------------------------------------------------------------------------------------------------------------------

 [ERROR] Found 1 error

After:

> phpstan analyze src/Config/Registrar.php

 1/1 [============================] 100%

 [OK] No errors

src/Config/Registrar.php Outdated Show resolved Hide resolved
@datamweb
Copy link
Owner Author

datamweb commented Nov 11, 2022

Before:

P:\WorkApp\cv472\vendor\datamweb\shield-oauth>composer analyze src\Config\Services.php
 1/1 [============================] 100%

 ------ --------------------------------------------------------------------------------------------------
  Line   Services.php
 ------ --------------------------------------------------------------------------------------------------
  21     Method Datamweb\ShieldOAuth\Config\Services::ShieldOAuth() has no return type specified.
  21     Method Datamweb\ShieldOAuth\Config\Services::ShieldOAuth() has parameter $getShared with no type
         specified.
  27     Class Datamweb\ShieldOAuth\Libraries\Basic\ShieldOAuth does not have a constructor and must be
         instantiated without any parameters.
 ------ --------------------------------------------------------------------------------------------------

After:

> phpstan analyze src\Config\Services.php

Note: Using configuration file P:\WorkApp\cv472\vendor\datamweb\shield-oauth\phpstan.neon.dist.
 1/1 [============================] 100%

 [OK] No errors

datamweb and others added 3 commits November 12, 2022 00:44
Co-authored-by: MGatner <mgatner@icloud.com>

docs: fix phpstan error from `Config/Services.php`
@datamweb
Copy link
Owner Author

Before:

------ ---------------------------------------------------
 Line   Routes.php
------ ---------------------------------------------------
 14     Variable $routes might not be defined.
 15     Cannot call method allOAuth() on mixed.
 18     Cannot access property $call_back_route on mixed.
------ ---------------------------------------------------


[ERROR] Found 3 errors

After:

> phpstan analyze --xdebug src/Config/Routes.php
Note: Using configuration file P:\WorkApp\cv472\vendor\datamweb\shield-oauth\phpstan.neon.dist.
 1/1 [============================] 100%


 [OK] No errors

I got help from kenjis & paulbalandan , so thanks to them.

@datamweb
Copy link
Owner Author

Before:

 ------ ----------------------------------------------------
  Line   ShieldOAuthModel.php
 ------ ----------------------------------------------------
  28     Cannot access property $usersColumnsName on mixed.
  29     Cannot access property $usersColumnsName on mixed.
  30     Cannot access property $usersColumnsName on mixed.
 ------ ----------------------------------------------------

After:

 0/1 [>---------------------------]   0%

 [OK] No errors

@datamweb
Copy link
Owner Author

Before:

 ------ ----------------------------------------------------------------------------------------------------
  Line   2022-10-20-182737_ShieldOAuth.php
 ------ ----------------------------------------------------------------------------------------------------
  24     Access to an undefined property Datamweb\ShieldOAuth\Database\Migrations\ShieldOAuth::$first_name.
  24     Cannot access property $usersColumnsName on mixed.
  25     Access to an undefined property Datamweb\ShieldOAuth\Database\Migrations\ShieldOAuth::$last_name.
  25     Cannot access property $usersColumnsName on mixed.
  26     Access to an undefined property Datamweb\ShieldOAuth\Database\Migrations\ShieldOAuth::$avatar.
  26     Cannot access property $usersColumnsName on mixed.
  32     Access to an undefined property Datamweb\ShieldOAuth\Database\Migrations\ShieldOAuth::$first_name.
  37     Access to an undefined property Datamweb\ShieldOAuth\Database\Migrations\ShieldOAuth::$last_name.
  42     Access to an undefined property Datamweb\ShieldOAuth\Database\Migrations\ShieldOAuth::$avatar.
  56     Access to an undefined property Datamweb\ShieldOAuth\Database\Migrations\ShieldOAuth::$first_name.
  57     Access to an undefined property Datamweb\ShieldOAuth\Database\Migrations\ShieldOAuth::$last_name.
  58     Access to an undefined property Datamweb\ShieldOAuth\Database\Migrations\ShieldOAuth::$avatar.
 ------ ----------------------------------------------------------------------------------------------------

 [ERROR] Found 12 errors

After:

 1/1 [============================] 100%

 [OK] No errors

@datamweb
Copy link
Owner Author

Before:

> phpstan analyze --xdebug src\Libraries\Basic\ControllersInterface.php
 1/1 [============================] 100%

 ------ -----------------------------------------------------------------------------------------------------------------
  Line   ControllersInterface.php
 ------ -----------------------------------------------------------------------------------------------------------------
  19     Method Datamweb\ShieldOAuth\Libraries\Basic\ControllersInterface::redirectOAuth() has no return type specified.
  21     Method Datamweb\ShieldOAuth\Libraries\Basic\ControllersInterface::callBack() has no return type specified.
 ------ -----------------------------------------------------------------------------------------------------------------

 [ERROR] Found 2 errors

After:

> phpstan analyze --xdebug src\Libraries\Basic\ControllersInterface.php
 1/1 [============================] 100%

 [OK] No errors

@datamweb
Copy link
Owner Author

Before:

 ------ ---------------------------------------------------------------------------------------------------------------------------------------
  Line   ShieldOAuth.php
 ------ ---------------------------------------------------------------------------------------------------------------------------------------
  31     Call to an undefined static method CodeIgniter\Config\Factories::loadOAuth().
  48     Cannot access property $psr4 on mixed.
  72     Method Datamweb\ShieldOAuth\Libraries\Basic\ShieldOAuth::otherOAuth() return type has no value type specified in iterable type array.
         πŸ’‘ See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
 ------ ---------------------------------------------------------------------------------------------------------------------------------------


 [ERROR] Found 3 errors

After:

 1/1 [============================] 100%


 [OK] No errors

Note:

return $oauthClass = Factories::loadOAuth($className);

I tried my best not to use @phpstan-ignore-line, but method loadOAuth() doesn't really exist. So there seems to be no other way than using @phpstan-ignore-line to have it rejected by PHPStan.
However, I am not sure about this.

@datamweb datamweb added the code Quality tools php cs fixer, php unit test, phpcpd, PHPMD, PHPStan, Psalm and ... label Jan 15, 2023
@kenjis
Copy link
Contributor

kenjis commented Jan 17, 2023

Level 9 is too high.

phpstan.neon.dist:

parameters:
	tmpDir: build/phpstan
	level: 5
	paths:
		- src/
	bootstrapFiles:
		- vendor/codeigniter4/framework/system/Test/bootstrap.php
	excludePaths:
		- src/Config/Routes.php
		- src/Views/*
	ignoreErrors:
	universalObjectCratesClasses:
		- CodeIgniter\Entity
		- CodeIgniter\Entity\Entity
		- Faker\Generator
	scanDirectories:
		- vendor/codeigniter4/framework/system/Helpers
		- vendor/codeigniter4/settings/src/Helpers
	dynamicConstantNames:
		- APP_NAMESPACE
		- CI_DEBUG
		- ENVIRONMENT
		- CodeIgniter\CodeIgniter::CI_VERSION
$ XDEBUG_MODE=off phpstan analyse
...
 ------ ----------------------------------------------------------------------------------------------------------------------- 
  Line   Controllers/OAuthController.php                                                                                        
 ------ ----------------------------------------------------------------------------------------------------------------------- 
  22     Return type mixed of method Datamweb\ShieldOAuth\Controllers\OAuthController::redirectOAuth() is not covariant with    
         return type CodeIgniter\HTTP\RedirectResponse of method                                                                
         Datamweb\ShieldOAuth\Libraries\Basic\ControllersInterface::redirectOAuth().                                            
  48     Return type mixed of method Datamweb\ShieldOAuth\Controllers\OAuthController::callBack() is not covariant with return  
         type CodeIgniter\HTTP\RedirectResponse of method                                                                       
         Datamweb\ShieldOAuth\Libraries\Basic\ControllersInterface::callBack().                                                 
  84     Parameter #1 $name of function model expects class-string<CodeIgniter\Model>, string given.                            
  91     Call to an undefined method CodeIgniter\Model::findById().                                                             
  94     Call to an undefined method CodeIgniter\Model::addToDefaultGroup().                                                    
  124    Parameter #1 $name of function model expects class-string<CodeIgniter\Model>, string given.                            
  126    Call to an undefined method CodeIgniter\Model::findByCredentials().                                                    
  133    Parameter #1 $name of function model expects class-string<CodeIgniter\Model>, string given.                            
  134    Call to an undefined method CodeIgniter\Model::findByCredentials().                                                    
  147    Class Datamweb\ShieldOAuth\Controllers\LoginModel not found.                                                           
         πŸ’‘ Learn more at https://phpstan.org/user-guide/discovering-symbols                                                    
  147    Parameter #1 $name of function model expects class-string<CodeIgniter\Model>, string given.                            
  149    Call to an undefined method CodeIgniter\Model::recordLoginAttempt().                                                   
 ------ ----------------------------------------------------------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------------------------------- 
  Line   Libraries/Basic/AbstractOAuth.php                                                            
 ------ --------------------------------------------------------------------------------------------- 
  28     Access to an undefined property Datamweb\ShieldOAuth\Libraries\Basic\AbstractOAuth::$token.  
  33     Access to an undefined property Datamweb\ShieldOAuth\Libraries\Basic\AbstractOAuth::$token.  
 ------ --------------------------------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------------------------------- 
  Line   Libraries/GithubOAuth.php                                                                    
 ------ --------------------------------------------------------------------------------------------- 
  29     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$client.         
  31     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$config.         
  32     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$callbake_url.   
  33     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$client_id.      
  34     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$client_secret.  
  39     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$callbake_url.   
  39     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$client_id.      
  46     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$client.         
  48     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$client_id.      
  49     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$client_secret.  
  51     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$callbake_url.   
  59     Caught class Datamweb\ShieldOAuth\Libraries\Exception not found.                             
         πŸ’‘ Learn more at https://phpstan.org/user-guide/discovering-symbols                          
  60     Call to method getMessage() on an unknown class Datamweb\ShieldOAuth\Libraries\Exception.    
         πŸ’‘ Learn more at https://phpstan.org/user-guide/discovering-symbols                          
  71     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$client.         
  79     Caught class Datamweb\ShieldOAuth\Libraries\Exception not found.                             
         πŸ’‘ Learn more at https://phpstan.org/user-guide/discovering-symbols                          
  80     Call to method getMessage() on an unknown class Datamweb\ShieldOAuth\Libraries\Exception.    
         πŸ’‘ Learn more at https://phpstan.org/user-guide/discovering-symbols                          
  90     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$config.         
  91     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$config.         
  92     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$config.         
  102    Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$config.         
  103    Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$config.         
  104    Access to an undefined property Datamweb\ShieldOAuth\Libraries\GithubOAuth::$config.         
  108    Variable $usersColumnsName might not be defined.                                             
 ------ --------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------- 
  Line   Libraries/GoogleOAuth.php                                                                  
 ------ ------------------------------------------------------------------------------------------- 
  32     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GoogleOAuth::$client.       
  34     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GoogleOAuth::$config.       
  49     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GoogleOAuth::$client.       
  62     Caught class Datamweb\ShieldOAuth\Libraries\Exception not found.                           
         πŸ’‘ Learn more at https://phpstan.org/user-guide/discovering-symbols                        
  63     Call to method getMessage() on an unknown class Datamweb\ShieldOAuth\Libraries\Exception.  
         πŸ’‘ Learn more at https://phpstan.org/user-guide/discovering-symbols                        
  74     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GoogleOAuth::$client.       
  82     Caught class Datamweb\ShieldOAuth\Libraries\Exception not found.                           
         πŸ’‘ Learn more at https://phpstan.org/user-guide/discovering-symbols                        
  83     Call to method getMessage() on an unknown class Datamweb\ShieldOAuth\Libraries\Exception.  
         πŸ’‘ Learn more at https://phpstan.org/user-guide/discovering-symbols                        
  93     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GoogleOAuth::$config.       
  94     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GoogleOAuth::$config.       
  95     Access to an undefined property Datamweb\ShieldOAuth\Libraries\GoogleOAuth::$config.       
  106    Access to an undefined property Datamweb\ShieldOAuth\Libraries\GoogleOAuth::$config.       
  107    Access to an undefined property Datamweb\ShieldOAuth\Libraries\GoogleOAuth::$config.       
  108    Access to an undefined property Datamweb\ShieldOAuth\Libraries\GoogleOAuth::$config.       
  112    Variable $usersColumnsName might not be defined.                                           
 ------ ------------------------------------------------------------------------------------------- 

                                                                                                                        
 [ERROR] Found 52 errors  

@datamweb datamweb mentioned this pull request Apr 3, 2023
2 tasks
@kenjis kenjis mentioned this pull request Aug 23, 2023
@datamweb datamweb closed this Aug 23, 2023
@datamweb datamweb deleted the docs-remove-phpstan-issues branch August 28, 2023 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code Quality tools php cs fixer, php unit test, phpcpd, PHPMD, PHPStan, Psalm and ...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants