224 questions
3 votes
1 answer
94 views
PHP Rector + PHPStan conflict in rules
I migrated project from PHP 7.4 to 8.3. I have left with 1 error in rector that I am not able to solve. $namesArray = explode($separator, $names); $namesArray = explode($separator, (string) $...
1 vote
1 answer
180 views
Why isn't PHPStan complaining about invalid array keys?
Here's the code: <?php declare(strict_types=1); /** * @param array{key?: string} $options */ function hello($options) { var_dump($options); } hello([ 'WRONG_KEY' => '...', ]); I ...
0 votes
2 answers
90 views
Insufficient Property Type in StdClass
I've got various instances of code, building options for a dropdown dynamically with a preceding empty field: return State::all() ->map(fn (State $state) => (object) [ ...
0 votes
1 answer
298 views
phpstan generics and factory return type
I do not understand why phpstan (at level 9+) flags the concrete factory's makeCollection method (the last class) as returning Collection. <?php declare (strict_types=1); /** * @template ...
0 votes
1 answer
301 views
Carbon macro not validated by PHPStan
I'm registering a custom Carbon macro in my Laravel's AppServiceProvider Carbon::macro('itFormat', static function () { return ucwords(self::this()->translatedFormat('l d/m/Y')); }); But ...
0 votes
1 answer
101 views
Writing a less brittle test for a custom PHPStan rule
I wrote a custom PHPStan rule, and a test for it. The test analyses a sample PHP class: class CustomRuleTestData { public function hasViolations() { // } public function ...
1 vote
0 answers
103 views
PHPStan not recognizing type specification for generic type
PHPStan is not recognizing my type specification in my docblock preceeding a method. Here's the code: /** * Process (resize and save) all versions of an uploaded file * * @param UploadedFileInterface ...
1 vote
0 answers
134 views
phpstan: assign.readOnlyProperty
The following class <?php namespace App; use Illuminate\Support\Str; use stdClass; class Payload { private(set) readonly array $validation; private array $ids = []; public ...