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

I use LARAVEL 9 and PHPSTAN I have this simple test method : public function createAndAuthenticatedAnUser(string $status = 'VALIDATED', bool $isAdmin = false): User { $user = User::factory()->...
Dom's user avatar
  • 3,506
0 votes
1 answer
3k views

I receive an error from PHPStan: Property App\Entity\Product::$productArticles type mapping mismatch: property can contain Doctrine\Common\Collections\Collection but database expects ...
Kuba5822's user avatar
1 vote
0 answers
3k views

I'm struggling to understand the cause of PHPStan error on method FooArray::this_doesnt_work. PHPDoc tag @return with type FooArray<int|string, TValueIn> is incompatible with native type static(...
Furgas's user avatar
  • 2,854
2 votes
1 answer
871 views

I'm looking at a Database ORM that uses an array to define the WHERE clause, e.g. $articles->find('all', [ 'OR' => [ 'category_id IS NULL', 'category_id' => $id, ], ]); ...
Craig Francis's user avatar
-2 votes
1 answer
79 views

I was made a mistake yesterday and spent hours to fix it. I have method like this { if (isset($data['y'])) { $this->y = $data['y']; } if (isset($data['z'])) { $this->...
Vladimir Martsul's user avatar
1 vote
1 answer
660 views

I spent time reading PHPStan documentation and trying, but I don't understand how to get the child class detected by PHPStan in this code, or even if it is possible... <?php declare(strict_types = ...
Romaric's user avatar
  • 11
4 votes
2 answers
3k views

I am using PHPStan with its Doctrine extension. I have a custom entity repository called App\Repository\Doctrine\UserRepository with the @extends doc block: /** * @extends \Doctrine\ORM\...
amacrobert's user avatar
  • 3,279
3 votes
1 answer
5k views

I am having a hard time making larastan / phpstan understand that query() should be based on Company model and not Eloquent\Model. What am I missing? <?php namespace App\Repositories; use App\...
Nicolas's user avatar
  • 2,834
5 votes
1 answer
5k views

I'm experimenting with PHP enums in a Symfony 6 application and I thought I found a very nice use case for those. Everything works, but phpstan keeps complaining about the type I return. ------ ------...
Julien B.'s user avatar
  • 3,374
-1 votes
1 answer
264 views

I have some PHP code that looks like this: class MyClass { public static function classPhpdoc($paramA) { return <<<PHP /** @template-extends \\$baseClass */ PHP; } } It'...
Radu Murzea's user avatar
1 vote
1 answer
3k views

I've created a function in my repository : /** * @return array<int, array<int, string>> */ public function findByBuildingGroupByCompany(string $buildingId): array { ...
user avatar
0 votes
1 answer
278 views

I am using both phpstan and apidoc, but i have an error on phpstan that i can't find a way to solve or ignore. Error message "Internal error: [Semantical Error] The annotation "@apiDefine&...
Gregory Boutte's user avatar
0 votes
1 answer
84 views

I have this code, part of a function I use to determine if a given string is a reserved PHP keyword (since PHP has no function for this built in): $tokens = token_get_all('<?php ' . $string . '; ?&...
John Doe's user avatar
3 votes
1 answer
3k views

Is there a way to specify that a function will return an object of a specific type, where the type is the string of one of the parameters? e.g. /** * @return object<$class> */ public function ...
useless's user avatar
  • 1,904
0 votes
2 answers
2k views

I’m trying to up my phpstan setup to level 3, but I’m getting an error like this: Property Something::$repository (SpecificRepository) does not accept RepositoryInterface. On a class that looks like ...
sylbru's user avatar
  • 1,631
0 votes
1 answer
718 views

I'm using doctrine in a project (not symfony). In this project I also use phpstan, i installed both phpstan/phpstan-doctrine and phpstan/extension-installer. My phpstan.neon is like this: parameters: ...
Gregory Boutte's user avatar
2 votes
0 answers
1k views

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 ...
user avatar
0 votes
0 answers
97 views

Why does phpstan dislike the definition of foo. That's not a wrong code, or is it? Although logical if shorthands are difficult to read and are very error-prone. <?php declare(strict_types = 1); ...
Markus's user avatar
  • 63
-1 votes
3 answers
615 views

I am having issue getting the return type for this function as I have mixed types in the switch. I have used mixed, it blew up. I have used string|bool and several type for union type. * @param $...
Curtis Lanz's user avatar
4 votes
2 answers
3k views

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 ...
user17535142's user avatar
2 votes
1 answer
15k views

I have a lot of while (1) and if (1) etc. in my code. PHPStan thinks these are errors, saying things such as While loop condition is always true. or If condition is always true.. I don't want to turn ...
user17535142's user avatar
3 votes
3 answers
12k views

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 ...
user842225's user avatar
  • 6,129
0 votes
0 answers
1k views

I've tried looking at a lot of solutions and still can't seem to find a fix for my issue. I keep getting the following error: Parameter #2 $string of function explode expects string, SimpleXMLElement|...
Nathan Bayne's user avatar
10 votes
4 answers
12k views

I am using PHP8, symfony5 and doctrine2 with phpstan and getting these errors: Property App\Entity\User::$id is never written, only read. The code: <?php namespace App\Entity; use App\...
ivoba's user avatar
  • 6,046
2 votes
1 answer
2k views

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->...
Rhys's user avatar
  • 51
1 vote
0 answers
592 views

I am new to PHPStan and I encountered an issue that I can't understand. So I have a function, that supposed to return an array that looks like this: array<a|b|c|d..., mixed> (a,b,c,d are all ...
Dániel Kónya's user avatar
1 vote
1 answer
822 views

I have this structure : apps - project_1 - app - vendor - project_2 - app - vendor - project_3 - app - vendor phpstan.neon composer.json I can’t run PHPStan at the root of "...
Mitsukk's user avatar
  • 321
5 votes
2 answers
3k views

I'm sure that question has been asked numerous times but I can't seem to find a good/satisfying answer so please bare with me. Using PHP 7.4+, I tend to type everything I can. But I have some problems ...
Julien B.'s user avatar
  • 3,374
1 vote
1 answer
1k views

We have a Laravel 8 application. We're using the standard Laravel Auth facade to retrieve the authenticated user. Our User model has a few custom functions, the most important of which is a shorthand ...
haz's user avatar
  • 1,646
3 votes
2 answers
7k views

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: ------ ---------------------------------------------------...
Reflexecute's user avatar
1 vote
1 answer
102 views

I'm using the login_link (docs) to authenticate an user who forgot his password. Following the docs, I customized the email and I override the htmlTemplate but in real life phpStan stop me saying : ...
Micka Bup's user avatar
  • 439
0 votes
1 answer
270 views

I am having a lot of trouble getting PHPStan to see the FuelPHP core classes. It would appear this sort of thing causes it grief: namespace Fuel\Core; /** * Template Controller class * * A base ...
Simon Parker's user avatar
  • 1,886
0 votes
1 answer
614 views

I'm using Gitlab to deploy my codebase. Each time, I deploy a branch (in fact multiple times by day), my CI do the following things (very simplified) : #1 Create a specific deploy folder with my ...
kero_zen's user avatar
  • 694
0 votes
1 answer
1k views

Working my way through the levels of PHPStan with a new applicaton, I got to level 3 and started getting error messages from all my test fixtures for models. The basic format is as follows: ------ ...
tjb74's user avatar
  • 67
0 votes
1 answer
3k views

I have this particular code: <?php declare(strict_types = 1); interface ObjectManager { /** * @param string $className The class name of the object to find. * @param mixed $id ...
Jazi's user avatar
  • 6,762
0 votes
0 answers
158 views

I'm fixing a platform which uses Symfony 2.8, with the help of PHPStan (PHP 7.1). I started with the last version of it (0.12.91), and it was great for the first two levels (0, 1). Level 2 wants to ...
Francois Verollet's user avatar
1 vote
1 answer
927 views

I have a PHP program, <?php class Zap { } class Zip { public Zap $zap; } $object = new Zip; var_dump( $object->zap ); This program produces an error because of an initialized non-...
Alana Storm's user avatar
1 vote
1 answer
1k views

in gitlab, I have a pipeline which generate a code climate report, supposed to be displayed in the gitlab widget. The report is successfully generated (I added cat code-quality.json but I have the ...
Asenar's user avatar
  • 7,086
1 vote
2 answers
1k views

I'm working on a Laravel application. In Laravel you can get the currently authenticated user with Auth::user(). The return type of Auth::user() is Authenticatable (which is an interface provided by ...
Lars Nyström's user avatar
1 vote
1 answer
86 views

i have string of html which i want to explode by <br>, but sometimes it can be inside of other tags. if (in_array($param, $customOrdering, true) && $value) { $ordering = array_search(...
petrspi's user avatar
  • 13
0 votes
0 answers
1k views

I know it's probably a silly question, but I'm struggling with it since a few hours and I can't manage to fix this error. I am using https://github.com/CakeDC/Enum in one of my projects. In my src/...
ToX 82's user avatar
  • 1,084
4 votes
1 answer
7k views

Given my class <?php declare(strict_types=1); use Illuminate\Support\Collection; use stdClass; class PhpstanIssue { /** * @param Collection<Collection<stdClass>> $collection ...
k0pernikus's user avatar
  • 67.6k
2 votes
1 answer
407 views

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 ...
AlexMakII's user avatar
1 vote
1 answer
17k views

I am on php 7.4 and using phpstan action in github (latest) actions-x/phpstan@v1 I am getting the following error return type has no value type specified in iterable type array on the following ...
Itay Moav -Malimovka's user avatar
0 votes
0 answers
99 views

I have a problem with an error that phpstan brings me up. It's about a load method in a datafixtures.php files. Here is the error : Parameter #1 $manager (Doctrine\Persistence\ObjectManager) of ...
AastroLePetitRobot's user avatar
3 votes
0 answers
487 views

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 phar:///...
David Albrecht's user avatar
0 votes
1 answer
956 views

I'm trying out phpstan and psalm for php and I would like to write a class that can take different type of objects and return the right one based on the factory to call. What I'm trying to achieve is ...
Full's user avatar
  • 475
5 votes
1 answer
2k views

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

I am trying to get static PHP code analysis to work on my OXID 6 eshop. I am, however, hitting a brick wall when it comes to this: When I run vendor/bin/phpstan analyse --configuration phpstan.neon ...
Taxel's user avatar
  • 4,217
0 votes
1 answer
582 views

I everyone, I have this simple try catch snippet, written in PHP : try { ... // some code ... } catch (Throwable $e) { $response = ['message' => $e->getMessage(...
Héouais Mongars's user avatar