PHPstan is an open-source static analyzer for PHP.
Questions tagged [phpstan]
36 questions
8
votes
2 answers
phpstan complains about Doctrine Migrations in Symfony 3.4 with Flex project
I have a project built on Symfony 3.4 with Flex and I've added phpstan to it for static analysis.
It is complaining about not finding my migration classes:
Class DoctrineMigrations\Version20180831185050 was not found while trying to analyse it -…
![](../../users/profiles/380140.webp)
Radu C
- 1,222
- 12
- 28
5
votes
2 answers
PHPStan: Property with generic class does not specify its types: TKey, T
I'm running PHPStan on a Symfony project where I have the following relation in a Doctrine entity:
/**
* @ORM\OneToMany(targetEntity="App\Entity\Course\Slide", mappedBy="chapter", cascade={"persist"}, orphanRemoval=true)
*…
![](../../users/profiles/6349751.webp)
AymDev
- 3,440
- 2
- 24
- 42
4
votes
1 answer
How to configure PHPStan to avoid false positives caused by specific classes and/or magic methods?
While using PHP RedBean on a project, PHPStan reports problems like this one:
87 Access to an undefined property RedBeanPHP\OODBBean::$token.
This is happening because RedBean's OODBBean class uses magic methods to logically bind class…
![](../../users/profiles/408195.webp)
Diogo Melo
- 1,171
- 3
- 13
- 25
3
votes
2 answers
Undefined variable in PHPStan but it's declared elsewhere
How do you deal with these scenarios in PHPStan:
Say you're using plain PHP as template engine. E.g.,
// view.php
=$foo?>
Say you have 2 files a.php and b.php
// a.php
$foo = 'bar';
// b.php
require 'a.php';
echo…
![](../../users/profiles/748789.webp)
IMB
- 12,083
- 16
- 59
- 118
3
votes
1 answer
PHPStan, exclude all and specify files to check
Im trying to setup PHPStan on a older, bigger, codebase. How could i exclude everything and than maybe by config define what to analyse.
I have thought about using a separate folder for it, but that would mean constantly moving files which might…
![](../../users/profiles/660410.webp)
Michal
- 940
- 1
- 7
- 18
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…
![](../../users/profiles/6475050.webp)
David
- 21
- 3
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
*…
![](../../users/profiles/11867424.webp)
Victor MGE
- 21
- 4
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] =…
![](../../users/profiles/15401093.webp)
petrspi
- 13
- 2
1
vote
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…
![](../../users/profiles/5354160.webp)
David Albrecht
- 494
- 1
- 3
- 15
1
vote
1 answer
How can I have phpstan find my custom extension class?
To implement checks for some magic _get() functions, I'm trying to implement a "class reflection extension". The manual mentions how to write the extension files themselves, and to install them by adding a service part to the neon file.
I've written…
![](../../users/profiles/546999.webp)
Nanne
- 61,952
- 16
- 112
- 157
1
vote
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:…
![](../../users/profiles/8032076.webp)
mehlichmeyer
- 82
- 14
1
vote
0 answers
PHP type hinting inline when calling a function
Is it possible to type hint a parameter directly inline during a function call?
public function load(ObjectManager $manager)
{
$product = $this->createProduct(
"T-SHIRT",
$this->getReference('brand-4') /** @var Brand <=== NOT…
![](../../users/profiles/757815.webp)
StockBreak
- 2,528
- 1
- 26
- 48
1
vote
1 answer
Problem with phpStan error : __toString() should return string but returns string|false
My function is __toString:
public function __toString(): string
{
return json_encode($this->payload);
}
This is the error that I receive from PhpStan, blocking me from making a commit:
Method App\DTO\GenericMessageDTO::__toString() should…
![](../../users/profiles/12027200.webp)
Ivan MIhael Čergar
- 23
- 4
1
vote
0 answers
How to represent a non-empty array?
I tried using intersection of types
/**
* @param array&nonEmpty $users
*/
function sayHello($users): void {
echo 'Hello, ' . $users[0];
}
but it complains:
PHPDoc tag @param for parameter $users contains unresolvable type.
(live demo)
If I…
![](../../users/profiles/160386.webp)
Jan Tojnar
- 4,640
- 3
- 25
- 44
1
vote
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:
-…
![](../../users/profiles/7603135.webp)
Timur
- 393
- 3
- 10