PHPstan is an open-source static analyzer for PHP.
Questions tagged [phpstan]
150 questions
1
vote
1 answer
Make PHPStan understand Laravel Eloquent Builder query()
I am having a hard time making larastan / phpstan understand that query() should be based on Company model and not Eloquent\Model. What am I missing?

Nicolas
- 2,754
- 6
- 26
- 41
1
vote
1 answer
Handle a phpstan error level 9 about array
I've created a function in my repository :
/**
* @return array>
*/
public function findByBuildingGroupByCompany(string $buildingId): array
{
return $this->createQueryBuilder('qr')
…
user18233136
1
vote
1 answer
defining generic return for a method/function in php with phpdocblock
Is there a way to specify that a function will return an object of a specific type, where the type is the string of one of the parameters?
e.g.
/**
* @return object<$class>
*/
public function create(string $class): object {
... some factory…

useless
- 1,876
- 17
- 18
1
vote
0 answers
How to make PHPStan ignore specific code snippets (not certain errors)?
I have a lot of while (1) and if (1) etc. in my code. PHPStan thinks these are errors, saying things such as While loop condition is always true. or If condition is always true..
I don't want to turn off those errors, because there could be valid…

user17535142
- 71
- 1
- 6
1
vote
0 answers
Method ... should return array but returns array('key1'=>SomeObject|null,'key2'=>SomeObject2|null)
I am new to PHPStan and I encountered an issue that I can't understand.
So I have a function, that supposed to return an array that looks like this: array (a,b,c,d are all class constants), but in the function, the array looks…

Dániel Kónya
- 11
- 1
1
vote
1 answer
Set multiple bootsrap files with PHPStan
I have this structure :
apps
- project_1
- app
- vendor
- project_2
- app
- vendor
- project_3
- app
- vendor
phpstan.neon
composer.json
I can’t run PHPStan at the root of "apps" to analyze my projects 1, 2 3 etc ... I have…

Mitsukk
- 314
- 2
- 13
1
vote
1 answer
Resolve Laravel Auth Authenticatable to User model to address static analysis issues
We have a Laravel 8 application.
We're using the standard Laravel Auth facade to retrieve the authenticated user.
Our User model has a few custom functions, the most important of which is a shorthand function, hasPermissionTo(). (The reason why is…

haz
- 1,549
- 15
- 20
1
vote
1 answer
How to pass phpStan with a customLoginLinkNotification?
I'm using the login_link (docs) to authenticate an user who forgot his password.
Following the docs, I customized the email and I override the htmlTemplate but in real life phpStan stop me saying :
Call to an undefined method…

Micka Bup
- 391
- 1
- 9
1
vote
1 answer
Can phpstan detect "Typed property ... must not be accessed before initialization" Errors?
I have a PHP program,
zap
);
This program produces an error because of an initialized non-nullable property.
Fatal error: Uncaught Error: Typed…

Alana Storm
- 164,128
- 91
- 395
- 599
1
vote
1 answer
Failed to load codeclimate report, but report exists
in gitlab, I have a pipeline which generate a code climate report, supposed to be displayed in the gitlab widget.
The report is successfully generated (I added cat code-quality.json but I have the message «Failed to load codeclimate report».
When I…

Asenar
- 6,732
- 3
- 36
- 49
1
vote
1 answer
How can I configure return type of third party method with phpstan?
I'm working on a Laravel application. In Laravel you can get the currently authenticated user with Auth::user(). The return type of Auth::user() is Authenticatable (which is an interface provided by Laravel), but I know this function will always…

Lars Nyström
- 5,786
- 3
- 32
- 33
1
vote
1 answer
phpstan not pass over strip_tags
i have string of html which i want to explode by
, but sometimes it can be inside of other tags. if (in_array($param, $customOrdering, true) && $value) { $ordering = array_search($param, $customOrdering, true); $segments[$ordering] =…
, but sometimes it can be inside of other tags. if (in_array($param, $customOrdering, true) && $value) { $ordering = array_search($param, $customOrdering, true); $segments[$ordering] =…

petrspi
- 13
- 2
1
vote
1 answer
"return type has no value type specified in iterable type array." error does not reflect reality?
I am on php 7.4 and using phpstan action in github (latest) actions-x/phpstan@v1
I am getting the following error
return type has no value type specified in iterable type array
on the following method:
class A{
/**
* @return array
…

Itay Moav -Malimovka
- 52,579
- 61
- 190
- 278
1
vote
1 answer
phpstan: how to handle derived class return types
What's the right way to fix the error generated by phpstan for this sample code? The error message is:
Method Foo::foo() should return Child but returns Base.

CXJ
- 4,301
- 3
- 32
- 62
1
vote
2 answers
Correct type hint error thrown by PHPStan on UserInterface in Symfony project
I've recently started using PHPStan (version 0.12.19) on a Symfony 3.4 project but I'm getting an error which seems like it should have been simple to resolve but I'm struggling to figure out.
Currently running at level 7. Here's the error I get…

BT643
- 3,495
- 5
- 34
- 55