Closed kenjis closed 1 year ago
You can turn this rule off:
Checks if the string argument passed to
config()
ormodel()
function is a valid class string extendingCodeIgniter\Config\BaseConfig
orCodeIgniter\Model
, respectively. This can be turned off by settingcodeigniter.checkArgumentTypeOfFactories: false
in yourphpstan.neon
.
The config also disables the config()
class checks like the following:
------ ---------------------------------------------------------------------------------
Line app/Controllers/Home.php
------ ---------------------------------------------------------------------------------
11 Argument #1 $name ('Config\\Modules') passed to function config does not extend
CodeIgniter\\Config\\BaseConfig.
------ ---------------------------------------------------------------------------------
This is conditionally activated here: https://github.com/CodeIgniter/phpstan-codeigniter/blob/d4f77abcd44672075342e2b8647f583b734671c4/extension.neon#L84-L85
If I understand correctly, you want to enable check for config()
but not for model()
. The non-BC way to do it that I can think of is too add 2 new options (added to extension.neon) that will be passed to the constructor of CodeIgniter\PHPStan\Rules\Functions\FactoriesFunctionArgumentTypeRule
. Then from there check if the resolved function name is either config
or model
then check if the user wants to bypass the check using the 2 new constructor parameters.
you want to enable check for config() but not for model().
Yes!
config()
checking is needed if we use Config caching, and using config()
to non-BaseConfig class is probably meaningless and using new
is faster.
But model()
checking is not needed. Because CodeIgniter does not force us to extend the model.
https://codeigniter4.github.io/CodeIgniter4/models/model.html#manual-model-creation
By the way, what was the type checking for model() implemented for in the first place?
Because factories has a verifyInstanceof
option. The opt-out feature strictly checks the instance in case that option is used.
Think of it like "strict-rules" for this extension.
PHP Version
8.1
PHPStan CodeIgniter Version
v1.4.2.70400
PHPStan Version
1.10.39
What happened?
https://github.com/kenjis/forum-example/blob/37a339f050ee2c40ed452e6570cef188dc0f90a0/app/Controllers/ActionsController.php#L46 https://github.com/kenjis/forum-example/blob/37a339f050ee2c40ed452e6570cef188dc0f90a0/app/Models/NotificationMutedModel.php#L11
Minimum Reproduction Script
Expected Output
No error on ActionsController