Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
2k views

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 ...
Oli's user avatar
  • 2,504
2 votes
0 answers
1k views

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 ...
ionov-e's user avatar
  • 21
0 votes
1 answer
730 views

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 ...
neubert's user avatar
  • 17k
3 votes
2 answers
5k views

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 ...
Dom's user avatar
  • 3,506
0 votes
1 answer
291 views

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 $...
Yevgeniy Afanasyev's user avatar
10 votes
1 answer
6k views

How to deal with scopes in Laravel when analyzing code with phpstan/larastan? I'm getting this error: Call to an undefined method Illuminate\Database\Eloquent\Builder::active(). Do I need to typehint ...
Yevgeniy Afanasyev's user avatar
1 vote
1 answer
2k views

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 ...
Johan Buret's user avatar
3 votes
2 answers
4k views

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 (...
WebDevPassion's user avatar
0 votes
1 answer
1k views

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 ...
S. Imp's user avatar
  • 2,877
5 votes
2 answers
9k views

Background I am building a class for a laravel system. It is for casting the Ramsey\Uuid\Uuid type in laravel models. I also use phpstan and I seem to be having problems with the generics/templating. ...
elb98rm's user avatar
  • 840
1 vote
1 answer
2k views

I am searching for a way to check my PHP code for compatibility with different PHP versions. Especially compatibility to PHP version 7.2 - 8.1 is what I am looking for. At first I tried phpcs but the ...
maxhb's user avatar
  • 8,893
0 votes
1 answer
1k views

I am trying to store a key into my database and I want it to be encrypted and decrypted. So I use Laravel 9 mutator: https://laravel.com/docs/9.x/eloquent-mutators protected function privateKey(): ...
nwantiti's user avatar
0 votes
1 answer
706 views

I started using PHPStan with the WordPress Plugin Boilerplate project that can be found here. I am stuck in the class-plugin-name-loader.php file validation I solved these errors: 33 - Property ...
MasterRed's user avatar
0 votes
1 answer
942 views

Lets say you have 3 models like this class User extends AbstractModel { protected string $name = 'User'; } class Car extends AbstractModel { protected int $weels = 4; } class House ...
HashtagForgotName's user avatar
0 votes
1 answer
2k views

I have installed PHPStan in a project developed around 1.5 years ago. The files of project have both old and fresh code. I want PHPStan to analyze only the fresh code written from today onwards and ...
John Smith's user avatar
1 vote
3 answers
987 views

I have a function that checks if a value is null and after I call that function I use the value that is obviously not null. but phpstan still says it could be null. Do you guys have any solution for ...
Collin Ter Steege's user avatar
-1 votes
1 answer
2k views

I am blocked with some phpstan validation, I have this array: /** @var array<string, string|array<string>> $normalizedImage */ $normalizedImage = $this->normalizer->normalize($...
Vincent Decaux's user avatar
5 votes
1 answer
2k views

In my code, I call a method whose return value is typed as follows: /** * @return array<int, array<string,mixed>> */ public function fetchAllAssociative(): array; The subtype array<...
biera's user avatar
  • 2,699
0 votes
0 answers
220 views

I have used an interface and a trait to fulfill the interface. interface Attachable { public function getAttachment(); public function setAttachment($attachment); } trait HasAttachment { ...
Aashan Ghimire's user avatar
0 votes
0 answers
128 views

I have a abstract class User: abstract class User and a child of User, "Administrator": class Administrator extends User When i create a new Administrator and want to persist with this ...
Thomas Baier's user avatar
0 votes
1 answer
728 views

PHPStan can't find the classes I installed with pear. Why? How can I fix it? Steps Run: pear install HTTP_Request2-2.5.1 Check: pear config-get php_dir /usr/share/pear Check: php -i | grep ...
YujiSoftware's user avatar
  • 1,737
1 vote
1 answer
3k views

I have defined an interface for an ordered list. The class docblock looks like this: /** * Interface ListOrderedInterface * @template ListOrderedElement */ Within the method docblocks for this ...
Doug Wilbourne's user avatar
1 vote
0 answers
598 views

PHPStan analysis combined with symfony/phpunit-bridge raises Call to an undefined method errors. Is it possible to ignore these errors with simple PHPStan configuration?
David's user avatar
  • 2,883
1 vote
1 answer
2k views

I have an application where I define some variables in a file (a.php), then include this from another file (b.php). PHPStan is complaining about possibly undefined variables. Simplified example: a.php:...
Grodriguez's user avatar
  • 22.1k
0 votes
1 answer
241 views

I've just started using PhpStan. I want to bind a specific base interface to a template variable, but the namespace is ignored. Whatever I try, PhpStand looks in namespace A\... namespace A; use B\...
S. Parton's user avatar
  • 305
0 votes
2 answers
801 views

I do get a warning whenever I throw an exception in my code without explicitly stating it in the docblocs: I know this can be fixed by adding @throw tags, but the warning is actually not 100% true, ...
Adam's user avatar
  • 29.6k
0 votes
1 answer
697 views

I would like to use a different PHP version than my default in my current VScode workspace for PHPstan. PHPstan keeps using my default PHP version from my windows commandline. The error I get is; PHP ...
Maarten's user avatar
  • 516
1 vote
1 answer
3k views

I'm running PHPStan in my project on level 9 and I'm closing in on zero errors now. One problem I can't find a solution for though is in the CRUD part of my project. With >50 complex entities that ...
JamesApril's user avatar
0 votes
1 answer
3k views

I am developing a web app, trying to keep PHPstan's suggestions in check. I am having some difficulties with this method: /** * AJAX: deletes a work file * * @return \Cake\Http\Response|false */ ...
ToX 82's user avatar
  • 1,084
2 votes
0 answers
930 views

Current situation: I'm using PhpStorm and PHPstan. I want to start analysis via PhpStorm and want the output in PhpStorm's terminal. So far so good, that's not a problem. Now I want to use PHPstan's ...
t.refu's user avatar
  • 87
8 votes
1 answer
2k views

If, for example, I have a class like this: class Foo { /** * @var array<string, array{name: string, age: int}> */ private array $things; /** * @return array */ ...
Mark G's user avatar
  • 135
0 votes
1 answer
2k views

I recently started playing with PHPStan, and encountered a roadblock that I just cannot get past. Some visual aid might make this easier for me to explain. Class names are simplified to keep things ...
CristianHG's user avatar
1 vote
1 answer
2k views

I have a factory method whose signature is similar to this: /** * @param class-string $class * @param callable? $callback * @return static */ public function instance(string $class, callable? $...
Mark G's user avatar
  • 135
2 votes
1 answer
1k views

I'm getting a PHPStan error that I don't understand how to fix: Parameter #1 $length of function random_bytes expects int<1, max>, int given. The function is very simple: private function ...
Patrick Kenny's user avatar
0 votes
1 answer
1k views

I'm implementing PHPStan into my application and also testing Psalm for automatic fixes, however I'm unable to make them read entity class strings (with colon) fe: $repository = $this->em->...
Wojtek vanDer's user avatar
1 vote
1 answer
814 views

I have the following problem. When I run analyse on my src folder, I get this error ------ -------------------------------------------------------------------------------------------------------------...
balrcoding's user avatar
0 votes
1 answer
4k views

I wanted to test my little symfony project today with PHPStan, and I got this error when I want to test User Entity (Entity/User.php), which I don't have clue what does it mean: 89 Method App\...
balrcoding's user avatar
0 votes
0 answers
758 views

I have trouble passing PHPStan tests because of parent/child classes (besides, code runs well). These two kind of errors always show up: Parameter #1 $a of method xxx expects ConcreteChildClass, ...
PLG's user avatar
  • 1
0 votes
0 answers
1k views

Say I have a formatter function like this: function prepareValue(mixed $value): string { ... return "{$value}"; } /** * @param array<int, array> $astTreeData * @return ...
wakh's user avatar
  • 1
0 votes
1 answer
556 views

For a php project, for some time my tests fail for phpstan and psalm, with unclear error messages. I tried to debug, to rebuild the commits, but without success. I can't understand or so. These are ...
Mirko Pagliai's user avatar
-1 votes
1 answer
2k views

I am getting a lot of errors related to phpunit like Class MyTest extends unknown class PHPUnit\Framework\TestCase or Call to an undefined method MyTest::assertFalse(). I am on Symfony 6 and use ...
Brucie Alpha's user avatar
  • 1,246
0 votes
1 answer
1k views

I'm getting this error: Cannot call method getClientOriginalExtension() on array<int, Illuminate\Http\UploadedFile>|Illuminate\Http\UploadedFile|null. when I run phpstan this's code: $...
jhon jhon's user avatar
-2 votes
1 answer
3k views

I'm running php ./vendor/bin/phpstan analyse --error-format github I get this issues: ::error file=app/Models/User.php,line=55,col=0::Method App\Models\User::roles() return type with generic class ...
jhon jhon's user avatar
1 vote
1 answer
1k views

I am attempting to use the correct typings according to Doctrine and PHPStan, however with an entity relation, I can't seem to make it right. I am using PHP 8.1.6, Doctrine 2.6.3, PHPStan 1.7.3 and ...
Deep Frozen's user avatar
  • 2,075
1 vote
0 answers
1k views

I have an array like below: array [ "total" => 0, "seed" => 0, "stringKey1" => array<string, string>, "stringKey2" => array<...
anru 's user avatar
  • 1,414
1 vote
0 answers
700 views

TL;DR My questions being : Is it a good practice to have exceptions inside an overriden methods ? If so, how should I document and handle exceptions so that PHPStan doesn't block my pipelines ? If ...
Joey Peau's user avatar
0 votes
1 answer
1k views

Since PHPStan 1.6, it's possible to use Conditional Return Types, where I've been able to do things like: /** * @param string $x * @return ($x is literal-string ? literal-string : string) */ public ...
Craig Francis's user avatar
0 votes
0 answers
528 views

Because PHPStan is driving me nuts about this, I have to ask and hope someone has an answer: when querying the database, the result set is a list of EntityInterface objects. Then when I attempt to ...
Tom Belknap's user avatar
-1 votes
1 answer
851 views

I am using Phpstan on a Drupal project that needs to be updated; I have solved all the issues revealed by Phpstan except one and I don´t know the solution to that one. The error message is: Line ...
DWA's user avatar
  • 523
4 votes
1 answer
2k views

I'm having trouble making sense of this PHPStan error. PHPStan is saying I need to provide the class string of an EntityRepository of an object. I am providing the class string of a ...
amacrobert's user avatar
  • 3,279