0

I am using Laravel 10 + PHPStan.

When I use Resource with the Laravel code, then PHPStan sends me this error:

18     Access to an undefined property App\Http\Resources\LocationResource::$id.
19     Access to an undefined property App\Http\Resources\LocationResource::$name.
20     Access to an undefined property App\Http\Resources\LocationResource::$comment.
21     Access to an undefined property App\Http\Resources\LocationResource::$library_id.
22     Access to an undefined property App\Http\Resources\LocationResource::$created_at.

I know I can solve this issue with some annotations. But I do not want to use that. I prefer use the phpstan.neon file and declare inside which error phpstan must ignore. See the documentation here.

So my phpstan.neon file looks like that:

parameters:
paths:
    - app/
ignoreErrors:
    - '#Call to an undefined method [a-zA-Z0-9\\_::]#'
    - '#Access to an undefined property App\\Http\\Resources\\[a-zA-Z0-9]::#'

It is the second 'ignoreErrors' line which is not correct.

Which regex I must enter in this conf file to ignore these kinds of errors?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Dom
  • 2,984
  • 3
  • 34
  • 64
  • 1
    Because it is an API Resource, I would add `@mixin` to the class definition, usage is `@mixin CLASS`, doing so will help with `$this->property`, the IDE will understand it – matiaslauriti Apr 09 '23 at 18:35

1 Answers1

1

I found this solution , add this line in the phpstan.neon file in the "ignoreErrors" section :

# to ignore these errors :  Access to an undefined property App\Http\Resources\LocationResource::$id.
        - '#Access to an undefined property App\\Http\\Resources\\[a-zA-Z0-9::a-zA-Z]#'
Dom
  • 2,984
  • 3
  • 34
  • 64