Questions tagged [phpstan]

PHPstan is an open-source static analyzer for PHP.

150 questions
3
votes
1 answer

PHPStan error: Method should return specific types but returns mixed

I'm using PHPStan for static analysis in my PHP 8.4.2 project, and I'm encountering an issue with a class method that returns multiple types or null. Here's my method with type hints and PHPDoc comment: /** * Returns a value of the…
Scudo
  • 41
  • 4
3
votes
1 answer

Fix Laravel scope warnings of phpstan (or larastan)?

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 it somehow? I'm trying to avoid…
Yevgeniy Afanasyev
  • 37,872
  • 26
  • 173
  • 191
3
votes
0 answers

PHPStan cast to more specific array shape

In my code, I call a method whose return value is typed as follows: /** * @return array> */ public function fetchAllAssociative(): array; The subtype array describes the database record in a generic way. I…
biera
  • 2,608
  • 1
  • 24
  • 26
3
votes
0 answers

Cakephp 3.x => 4.0 migration: Fatal error in PHPStan\Analyser\MutatingScope

When I run the rector script bin/cake upgrade rector --rules cakephp40 ../project/src I get the following error: Notice: Undefined property: PhpParser\Node\Stmt\ClassMethod::$attrGroups in…
David Albrecht
  • 634
  • 1
  • 4
  • 15
2
votes
0 answers

Larastan Query Builder instance understanding orWhere preceeding Query Scope

I'm using Larastan to eliminate some of the static analysis errors I have going on in my codebase. I have several errors involving the the Eloquent Higher Order Messaging Proxy known as orWhere. I'm using this method as show…
user2576961
  • 405
  • 1
  • 10
  • 26
2
votes
2 answers

What is the format for PHPStan's "phpVersion" config option?

I've been searching and reading and hunting and pulling my hair. This is the only mention of phpVersion: https://phpstan.org/config-reference#phpversion If you want to analyse a codebase as if it was written for a different PHP version than you’re…
user17535142
  • 71
  • 1
  • 6
2
votes
3 answers

Why do I get error when try to convert Carbon to DateTime?

I am developing a Laravel project. I try to create a DateTime object by using Carbon. This is what I tried: Carbon::createFromFormat('Y-m-d H:i:s', '2021-10-01T00:01:00')->toDateTime(); But my phpstan complains : Cannot call method toDateTime() on…
user842225
  • 5,445
  • 15
  • 69
  • 119
2
votes
1 answer

PHP Laminas PHPStan - Call to an undefined method Laminas\Stdlib\RequestInterface::isPost()

We are running phpstan on a laminas project and running into errors. As an example, in the controller we have some standard code which works fine. $request = $this->getRequest(); if ($request->isPost()) { ... } However phpstan is…
Rhys
  • 41
  • 4
2
votes
2 answers

PHPStan ignore errors regex

Problem I recently started using PHPStan to analyse my code for my Laravel projects but I keep getting the following error for all my models: ------ -------------------------------------------------------------------- Line Models/Fund.php …
Reflexecute
  • 271
  • 4
  • 14
2
votes
1 answer

How to get phpstan to infer the type for my Laravel Collection pipeline?

Given my class > $collection * * @return Collection */ public…
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
2
votes
1 answer

How to say phpstan that class is replaced by child

I have a laravel package for logging. It's used like this. activity() ->performedOn($model) ->causedBy($user) ->log('Look, I logged something'); The activity() helper returns the vendor class ActivityLogger which is take from the container…
AlexMakII
  • 43
  • 5
2
votes
2 answers

Repository (Doctrine\ORM\EntityRepository) does not accept Doctrine\Persistence\ObjectRepository

When upgrading doctrine/persistence from 1.0 to 1.3 I encountered a problem with static code analysis. Repository (Doctrine\ORM\EntityRepository) does not accept Doctrine\Persistence\ObjectRepository. The problem…
David
  • 21
  • 5
2
votes
2 answers

Phpstan with gitlab-ci cant find srcApp_KernelDevDebugContainer.xml because its in the gitignore?

this is my phpstan.neon parameters: checkMissingIterableValueType: false checkGenericClassInNonGenericObjectType: false symfony: container_xml_path: '%rootDir%/../../../var/cache/dev/srcApp_KernelDevDebugContainer.xml' bootstrap:…
mehlichmeyer
  • 154
  • 1
  • 18
2
votes
1 answer

Problem creating an instance of ObjectStorage

In my domain model there is a property month which is an ObjectStorage for bill elements. Here is how the domain model looks: /** * establishment * * @var ObjectStorage *…
Victor MGE
  • 41
  • 6
2
votes
1 answer

PHPStan don't see proper ObjectManager for Doctrine

I try improve my code with PHPStan. I already install: PHPStan Doctrine extensions for PHPStan PHPStan PHPUnit extensions and rules PHPStan Symfony Framework extensions and rules Here my phpstan.neon: includes: -…
Timur
  • 488
  • 4
  • 14
1
2
3
9 10