Welcome Guest, Not a member yet? Register   Sign In
PHPStan return types when using model() helper
#1

(This post was last modified: 11-29-2021, 08:27 AM by aschmitz.)

Hi all,
with the changes here:
https://github.com/codeigniter4/CodeIgni...c5bf540a80
the
PHP Code:
model() 
helper  received the additional annotation
PHP Code:
@phpstan-return Model 
.

Now, PHPStan will complain whenever one tries to call a function of a model that is not the original CodeIgniter\Model but was invoked with the helper.
E.g.:

PHP Code:
Model:
    
use CodeIgniter\Model;
class 
TestModel extends Model{
    public function getCrudData(){
    }
}

Controller:

$model model(TestModel::class);
$data  $model->getCrudData(); 

This will trigger PHPStan:

PHP Code:
Call to an undefined method CodeIgniter\Model::getCrudData(). 

as it exepects a "CodeIgniter\Model".

Did anyone run into the same issue or am I misusing the helper function?

Thanks
Alex

Same goes, e.g., for Lonnies myth\auth library:
https://github.com/lonnieezell/myth-auth
Reply
#2

> am I misusing the helper function?

No.

This is an issue that we need a solution.
See https://github.com/codeigniter4/CodeIgniter4/pull/5358
Reply




Theme © iAndrew 2016 - Forum software by © MyBB