Larastan: Incorrectly determined a return class

Created on 9 Jan 2019  路  3Comments  路  Source: nunomaduro/larastan

  • Larastan Version: 0.3.13
  • --level used: 6

Description:

Hello Guys,

I am getting these errors on level 6

------ ------------------------------------------------------------------------------------------------------ 
  Line   app/Http/Controllers/OauthController.php                                                              
 ------ ------------------------------------------------------------------------------------------------------ 
  90     Access to private property $id of parent class Illuminate\Foundation\Auth\User.                       
  96     Access to private property $pid of parent class Illuminate\Foundation\Auth\User.                      
  104    Access to private property $email of parent class Illuminate\Foundation\Auth\User.                    
  105    Access to private property $language of parent class Illuminate\Foundation\Auth\User.                 
  106    Access to private property $currency of parent class Illuminate\Foundation\Auth\User.                 
  113    Call to an undefined method                                                                           
         (Illuminate\Database\Eloquent\Collection&iterable<static(App\User)>)|static(App\User)::getLogInfo().  
 ------ ------------------------------------------------------------------------------------------------------ 

The way i use these properties and the function is following...

$user = User::find($ID);  

$user->id;  

$user->pid;  

$user->getLogInfo();

So to sum it up, object properties are not defined, but even if i define them or specify them as a @parameter docs it has no effect. I think that the problem lies in a User::find() method where a static analyzer thinks that this method should return a Illuminate\Foundation\Auth\User but in a real life it returns App\User class...

Do you have an idea how to fix these errors?

Most helpful comment

You can tell PHPStan that find returns App\User by doing

/** @var \App\User|null $user */
$user = User::find($ID);

That's a temporary solution. But I hope it'll get fixed with #324

All 3 comments

What is your use?

You can tell PHPStan that find returns App\User by doing

/** @var \App\User|null $user */
$user = User::find($ID);

That's a temporary solution. But I hope it'll get fixed with #324

Smal nitpick 馃槃 : technically this is \App\User|null, unless you would use findOrFail

Was this page helpful?
0 / 5 - 0 ratings