Questions tagged [phpstan]

PHPstan is an open-source static analyzer for PHP.

150 questions
1
vote
1 answer

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…
StockBreak
  • 2,857
  • 1
  • 35
  • 61
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…
1
vote
1 answer

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…
Jan Tojnar
  • 5,306
  • 3
  • 29
  • 49
1
vote
0 answers

CakePHP Upgrade via Rector, functions with input type array declaration

I'm trying to use rector (https://github.com/rectorphp/rector) for the first time to upgrade my CakePHP application. I'm working in a local development environment first. I've hit a bit of a headache. For example purposes I created the following…
jtesta
  • 183
  • 3
  • 15
1
vote
1 answer

PHPstan rules to migrate from 7.0 to 7.2

Im wondering if there are any existing PHPStan rules / ruleset which checks a codebase for BC breaking changes when wanting to migrate from PHP 7.0 to PHP 7.2.
Michal
  • 1,010
  • 2
  • 8
  • 18
1
vote
1 answer

PHPStan - change type of constructor parameter

When running PHPStan on my codebase I get the error: Parameter #2 $credentials of class Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken constructor expects string, null given. This is because the constructor's docblock…
Dennis Haarbrink
  • 3,738
  • 1
  • 27
  • 54
0
votes
1 answer

Class object was not found while trying to analyse it - discovering symbols is probably not configured properly

I'm using PHP Stan on lvl 0 to analyse my code. I could fix everything except those 2 errors. I checked everything but the files are fine, also checked every use and the file itself. In the same folder there are like 100 more files with the same…
th3_sh0w3r
  • 37
  • 7
0
votes
0 answers

PHPStan error: Argument of an invalid type supplied for foreach, only iterables are supported

I'm stuck again at a point where I can't get any further. I'm working on the code of an ex colleague and try to fix the errors on PHPStan level 9. Since I am new to the world of PHP and PHPStan I need help. I am stuck on the following code: /** *…
0
votes
1 answer

PHPStan excludePaths is not working on vendor files

I am having this PHPStan error on our vendor files Command and Logger: ------ --------------------------------------------- Line ../www-vendor/symfony/console/Command/Command.php ------ --------------------------------------------- 378 …
0
votes
0 answers

Site down issue when running enlightn in laravel

I am trying to run the Enlightn package on my Laravel application using the following command: php artisan enlightn It is executing properly; however, it significantly slows down my application and sometimes even causes it to go down. After…
0
votes
1 answer

phpword 0.18.2 integration with phpstan

There are phpstan configuration files in the phpword sources https://github.com/PHPOffice/PHPWord/tree/0.18.2 , but composer does not include these on phpword installation, thus there are none of these in the vendor directory. [screenshot] Any…
0
votes
1 answer

Why does PHPStan error occur on GitLab pipeline for a WordPress project?

I have a Bedrock-based WordPress project that is Dockerized (WordPress core is pulled as a Composer dependency on local project). Among the dependencies, there is PHPStan, which works correctly without any errors locally. However, when the GitLab…
0
votes
1 answer

Why are my default argument values not being picked up by PHPStan?

Line base\Kader\Kader.php (in context of class Kader\Debugging) ------ ------------------------------------------------------------------------------ 107 Method Kader\Debugging::configDebug() invoked with 0 parameters, 2…
0
votes
0 answers

phpStan extende method return type

I have a class with two methods: toArray and collect where collect will return collection of array from method toArray responses. Is there any way in PHP Stan how to annotate return type for collect as array of toArray responses ? As shown in…
Dawenear
  • 91
  • 1
  • 1
  • 4
0
votes
1 answer

Rewriting PHPDocs based on the correct types

This might be a long shot, but maybe someone can help or have ideas. In Mautic, we are doing a lot of refactoring at the moment to upgrade the code base to be PHP 8.x one of the issues I am facing personally is that we have lots of classes with the…
Mohammad Abu Musa
  • 1,117
  • 2
  • 10
  • 32