Closed caugner closed 3 years ago
As for the NonInvariantDocblockPropertyType
error, this looks like a phpdoc bug in laravel/framework to me: description
is never really null
, because it is always set via setDescription()
in Illuminate\Console\Command::__construct().
edit 1: The same holds for Command::$help
, which is always set via setHelp()
.
In contrast, Command::$laravel
is actually null
on a newly constructed command object, before the property is set via setLaravel()
.
edit 2: Likewise, InteractsWithIO::$input
and InteractsWithIO::$output
are actually null
(or more precisely: unset) until they are set via setInput()
and setOutput()
.
Could we suppress the PropertyNotSetInConstructor
for these properties via the laravel plugin?
Am I correct in understanding that you got this fixed upstream in laravel? Anything left to do here?
@mr-feek I was only able to fix the NonInvariantDocblockPropertyType
error upstream, not the PropertyNotSetInConstructor
errors. 😕
artisan make:command Example
and assert that Psalm does not find any errors afterwards, or do we have to add such an Example[Command]
as a stub (which is less flexible, becaus it doesn't take into account changes to the make:command
command? Illuminate\Console\Command
that either (a) redefines those properties with @psalm-suppress PropertyNotSetInConstructor
, or (b) defines them as typed properties so that they are either unset or values of the annotated type?I just created my first FormRequest
(php artisan make:request ExampleRequest
) and it caused similar errors:
ERROR: PropertyNotSetInConstructor - app/Http/Requests/ExampleRequest.php:7:7 - Property App\Http\Requests\ExampleRequest::$container is not defined in constructor of App\Http\Requests\ExampleRequest and in any methods called in the constructor (see https://psalm.dev/074)
class ExampleRequest extends FormRequest
ERROR: PropertyNotSetInConstructor - app/Http/Requests/ExampleRequest.php:7:7 - Property App\Http\Requests\ExampleRequest::$redirector is not defined in constructor of App\Http\Requests\ExampleRequest and in any methods called in the constructor (see https://psalm.dev/074)
class ExampleRequest extends FormRequest
ERROR: PropertyNotSetInConstructor - app/Http/Requests/ExampleRequest.php:7:7 - Property App\Http\Requests\ExampleRequest::$redirect is not defined in constructor of App\Http\Requests\ExampleRequest and in any methods called in the constructor (see https://psalm.dev/074)
class ExampleRequest extends FormRequest
ERROR: PropertyNotSetInConstructor - app/Http/Requests/ExampleRequest.php:7:7 - Property App\Http\Requests\ExampleRequest::$redirectRoute is not defined in constructor of App\Http\Requests\ExampleRequest and in any methods called in the constructor (see https://psalm.dev/074)
class ExampleRequest extends FormRequest
ERROR: PropertyNotSetInConstructor - app/Http/Requests/ExampleRequest.php:7:7 - Property App\Http\Requests\ExampleRequest::$redirectAction is not defined in constructor of App\Http\Requests\ExampleRequest and in any methods called in the constructor (see https://psalm.dev/074)
class ExampleRequest extends FormRequest
ERROR: PropertyNotSetInConstructor - app/Http/Requests/ExampleRequest.php:7:7 - Property App\Http\Requests\ExampleRequest::$validator is not defined in constructor of App\Http\Requests\ExampleRequest and in any methods called in the constructor (see https://psalm.dev/074)
class ExampleRequest extends FormRequest
ERROR: PropertyNotSetInConstructor - app/Http/Requests/ExampleRequest.php:7:7 - Property App\Http\Requests\ExampleRequest::$convertedFiles is not defined in constructor of App\Http\Requests\ExampleRequest and in any methods called in the constructor (see https://psalm.dev/074)
class ExampleRequest extends FormRequest
ERROR: PropertyNotSetInConstructor - app/Http/Requests/ExampleRequest.php:7:7 - Property App\Http\Requests\ExampleRequest::$userResolver is not defined in constructor of App\Http\Requests\ExampleRequest and in any methods called in the constructor (see https://psalm.dev/074)
class ExampleRequest extends FormRequest
ERROR: PropertyNotSetInConstructor - app/Http/Requests/ExampleRequest.php:7:7 - Property App\Http\Requests\ExampleRequest::$routeResolver is not defined in constructor of App\Http\Requests\ExampleRequest and in any methods called in the constructor (see https://psalm.dev/074)
class ExampleRequest extends FormRequest
ERROR: PropertyNotSetInConstructor - app/Http/Requests/ExampleRequest.php:7:7 - Property App\Http\Requests\ExampleRequest::$session is not defined in constructor of App\Http\Requests\ExampleRequest and in any methods called in the constructor (see https://psalm.dev/074)
class ExampleRequest extends FormRequest
ERROR: PropertyNotSetInConstructor - app/Http/Requests/ExampleRequest.php:7:7 - Property App\Http\Requests\ExampleRequest::$locale is not defined in constructor of App\Http\Requests\ExampleRequest and in any methods called in the constructor (see https://psalm.dev/074)
class ExampleRequest extends FormRequest
There are also PropertyNotSetInConstructor
warnings when extending Illuminate\Foundation\Testing\TestCase
:
psalm: PropertyNotSetInConstructor: Property Tests\Feature\ExampleTest::$app is not defined in constructor of Tests\Feature\ExampleTest or in any private or final methods called in the constructor
psalm: PropertyNotSetInConstructor: Property Tests\Feature\ExampleTest::$backupStaticAttributes is not defined in constructor of Tests\Feature\ExampleTest or in any private or final methods called in the constructor
psalm: PropertyNotSetInConstructor: Property Tests\Feature\ExampleTest::$callbackException is not defined in constructor of Tests\Feature\ExampleTest or in any private or final methods called in the constructor
psalm: PropertyNotSetInConstructor: Property Tests\Feature\ExampleTest::$runTestInSeparateProcess is not defined in constructor of Tests\Feature\ExampleTest or in any private or final methods called in the constructor
Notifications are also affected by this.
Describe the bug
When I create a new command using
artisan make:command
, I get the following errors:Impacted Versions
Additional context For now, my workaround is
@psalm-suppress PropertyNotSetInConstructor
to the command class' doc block, and@var string
to@var string|null
for theprotected $description
property.However, this is a bit cumbersome and especially frustrating for new developers.