PHPstan is an open-source static analyzer for PHP.
Questions tagged [phpstan]
150 questions
0
votes
1 answer
PHPStan errors on Laravel Model relationships, any solutions?
PHPStan has found hundreds of errors in the Laravel project. Mostly, Access to an undefined property Illuminate\Database\Eloquent\Model::$id.
for constructs like
$project_id = $checkpoint->project->id;
Does PHPStan not understand the relationships…

Nikita P
- 11
- 1
0
votes
1 answer
Phpstan analysis fails as part of the Gitlab pipeline
Phpstan analysis fails when I run it as part of the Gitlab pipeline, it passes locally. I'm talking about the analysis and not the running of the command itself. I do not get 'command not found' or 'phpstan.neon' not found errors, but rather the…

Johnson55
- 1
- 1
0
votes
1 answer
Does PhpStan and Psalm measures cyclomatic complexity?
I've read the documentation from PhpStan and Psalm, and i couldn't find the rules where it checks the Cyclomatic Complexity like Phpmd does here
Also, is it possible to cusomise rules within levels for PhpStan and Psalm? Looking for a source.

Mali C.
- 11
- 4
0
votes
3 answers
How to write a rule to pass the Larastan test
I'm struggling with the return code of a validation rule to pass the "Larastan" test.
The code for this rule is:
public function rules(): array
{
return [
'name' => [
'required',
Rule::unique('domains',…

Dom
- 2,984
- 3
- 34
- 64
0
votes
0 answers
How to reach level 8 with larastan?
I'm trying to have super clean laravel code using larastan.
For the moment it is flawless up to level 7 (out of 9 possible). And I get stuck by going to 8 on this code:
$user = User::where('email', $request->email)->first();
if ($user) {
…

Dom
- 2,984
- 3
- 34
- 64
0
votes
1 answer
PhpStorm with PHPStan in Docker doesn't work
When using the System PHP interpreter for PHPStan, I get an error that the PHP version mismatches with the one being used in the Docker, see picture.
But when I set PHPStan to use the PHP interpreter inside the Docker container, I get an error…

Oli
- 2,370
- 2
- 26
- 42
0
votes
0 answers
phpstan throw an error to Eloquent\Builder::get()
I have this code

Richard
- 1
0
votes
0 answers
PSALM / PHPStan / PHPDoc Types: using templates/generics as array keys (of multiple elements array)
I cannot figure how to annotate an array returned from API Response.
Response have a structure:
array{'totalCount': numeric-string, $vehicleType: array}
Instead of variable $vehicleType there can be different keys. List of all possible keys…

ionov-e
- 1
- 1
0
votes
1 answer
denoting optional parameters via annotations for phpstan
I have a class that has a __call method. The first parameter to the __call method, per the PHP docs, is the method name. If the method name is unsupported I throw an exception.
The problem with this is that if I do vendor/bin/phpstan analyze…

neubert
- 15,947
- 24
- 120
- 212
0
votes
1 answer
How to ignore "access to an undefined property" using PHPStan and Laravel
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…

Dom
- 2,984
- 3
- 34
- 64
0
votes
1 answer
PHPstan does not like preg_match parameters
PHPstan gives this error
Parameter #4 $flags of function preg_match expects TFlags of 0|256|512|768, int given.
to this code
function my_preg_match(
string $pattern,
string $subject,
array &$matches = null,
int…

Yevgeniy Afanasyev
- 37,872
- 26
- 173
- 191
0
votes
1 answer
PhpStorm configuration of PHPstan for Symfony with Docker
I am trying to make PHPstan work for a dockerized Symfony project using this template. The project use PHP 8.1.16. Works fine.
Now I want to push it a little bit to fully use the PHP CLI installed in my docker container instead of the local one.
I…

Johan Buret
- 11
- 3
0
votes
2 answers
Describe an array containing an object (stdClass) with @phpstan-return in PHP DocBlock? - PHPStan
I have an example function in PHP (8.2) that returns an array. Inside this array there is also an object, more precisely stdClass.
I use PHPStan as a static analyzer tool. How can I specify this (object shapes) structure syntactically correct to use…

WebDevPassion
- 422
- 1
- 4
- 12
0
votes
1 answer
why is phpstan reporting a lot more errors on exact same src on macos vs ubuntu?
I've forked CodeIgniter 3 to work on PHP 8.2 compatibility. I'm using PHPStan for static analysis to try and identify all the referencees to undefined class properties, which seems to be the primary shortcoming. Unfortunately, I'm getting very…

S. Imp
- 2,833
- 11
- 24
0
votes
0 answers
grumphp - how to force all files in specific directory to start with uppercase
I'm using grumphp + phpcs and phpstan to enforce a consistent project structure.
Is there a way to use the current setup to ensure no developers create lowercase files? Have the rule for class name, but nothing for file name.

zozo
- 8,230
- 19
- 79
- 134