Skip to main content
Filter by
Sorted by
Tagged with
2 votes
1 answer
41 views

I'm trying to define a Laravel Eloquent model with a custom scope that filters categories by a related product's vendor_id. Here's my setup: class Category extends Model { public function ...
melkmeshi's user avatar
3 votes
1 answer
100 views

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) $...
tttpapi's user avatar
  • 939
2 votes
1 answer
102 views

I'm writing a custom PHPStan rule that suggests marking a class as readonly (introduced in PHP 8.2) when it meets all the necessary conditions. One of the requirements for safely applying readonly is ...
zeroSal's user avatar
  • 131
1 vote
1 answer
191 views

Here's the code: <?php declare(strict_types=1); /** * @param array{key?: string} $options */ function hello($options) { var_dump($options); } hello([ 'WRONG_KEY' => '...', ]); I ...
Limon Monte's user avatar
  • 54.8k
0 votes
2 answers
77 views

PHPstan seems to incorrectly narrow type after if (empty(...)). \PHPStan\dumpType($_GET); // array<mixed> if (empty($_GET['ssid'])) { /* do nothing */ } \PHPStan\dumpType($_GET); // non-...
Roman Hocke's user avatar
  • 4,241
0 votes
2 answers
91 views

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) [ ...
Rikaelus's user avatar
  • 627
1 vote
1 answer
129 views

My question to get code completion working in a set of classes that I have. + abstract Model :: make(array{...}) +- SubModel +- AnotherSubModel +- ... I have an abstract Model class, and ...
Andrew Steenbuck's user avatar
0 votes
1 answer
299 views

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

I need to run tests on a certain class, but adding a method that was not originally present. Previously this need could be satisfied using MockBuilder::addMethods(), but this method has been ...
Mirko Pagliai's user avatar
0 votes
1 answer
306 views

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 ...
madbob's user avatar
  • 660
1 vote
1 answer
965 views

I want to annotate function, tat takes array with at least key "a" and returns the same array shape with newly added key "x". I tried using type intersection like this: /** * @...
Roman Hocke's user avatar
  • 4,241
0 votes
1 answer
101 views

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 ...
Zakaria's user avatar
  • 4,776
2 votes
0 answers
158 views

Json-like structures are quite common in php applications that deal some sort of json api. The precise type of such a structure is recursive: /** * @return null|scalar|array< null|scalar|array< ...
linepogl's user avatar
  • 9,385
1 vote
0 answers
105 views

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 ...
Quasipickle's user avatar
  • 4,530
2 votes
1 answer
674 views

I am using larastan 3.0 with laravel. The level is 9. In this code : return view('auth.change-password', [ 'user' => $user, ]); I have this error : Parameter #1 $view of function view ...
Dom's user avatar
  • 3,506
1 vote
0 answers
137 views

The following class <?php namespace App; use Illuminate\Support\Str; use stdClass; class Payload { private(set) readonly array $validation; private array $ids = []; public ...
Sebastian Sulinski's user avatar
0 votes
1 answer
194 views

I’m encountering an issue while configuring PHPStan for a TYPO3 extension (TYPO3 v13.4.1, PHP 8.2, DDEV environment). I have a custom extension and need to configure PHPStan to use rules from an ...
Chanyss921's user avatar
0 votes
1 answer
1k views

My PHP version is 7.1.31 and Laravel version is 4.2. I want to use phpstan as my static analysis tool. When I run it, it outputs so many errors. Examples are: Call to an undefined method Illuminate\...
Raldsanity's user avatar
0 votes
1 answer
123 views

According to some conditions, I need to return int or Collection (the table data from mysql query or his count), Here is code what I did implemented. public function myMethod( Term $term, ...
ClusterH's user avatar
  • 955
0 votes
1 answer
567 views

After upgrading to phpstan-doctrine version 1.5.2 it is required to do the following changes: diff --git a/src/Repository/TagRepository.php b/src/Repository/TagRepository.php index 89bc22a..6f65925 ...
Anton's user avatar
  • 180
2 votes
1 answer
97 views

I have a problem with @return types. It seems that either it's a bug in PHPStan or I'm doing something wrong. Error: abstract class Aclass {} final class Bclass extends Aclass {} final class Cclass ...
Slava Basko's user avatar
1 vote
0 answers
175 views

I have a function that looks like this protected function getAllData(string $tableName, string $collectionKey): array { // Some logic here to get records from database and store them in $records......
Markus Bischof's user avatar
1 vote
0 answers
46 views

According to the CakePHP 4 docs // If you want a json response $response = $response->withType('application/json') ->withStringBody(json_encode(['Foo' => 'bar'])); If you run phpstan on ...
Andy's user avatar
  • 5,438
3 votes
1 answer
652 views

I'm working on a Laravel project and there happens to be a code snippet like this: sprintf("%s %s", __('foo.bar.buzz'), __('foo.bar.baz')); Note that the __ function is a helper function ...
Rexy's user avatar
  • 286
-1 votes
1 answer
1k views

I'm new to using PHPStan/Larastan and configured it based on their documentation. When I run PHPStan at level 8, it passes without errors However, when I set PHPStan to the maximum level, it generates ...
joy2362's user avatar
  • 73
0 votes
0 answers
96 views

I'm looking to enforce a specific method chaining style in PHP, particularly to differentiate between what I consider the 'wrong' and 'good' styles. Is there a tool or method that can help check and ...
Stevan Tosic's user avatar
  • 7,317
0 votes
2 answers
68 views

Let's say I have two configuration NEON files: config1.neon parameters: excludePaths: - path1 config2.neon includes: - "config1.neon" parameters: excludePaths: - ...
Roman Hocke's user avatar
  • 4,241
0 votes
1 answer
2k views

I have a section of code as follows $decodedCredentials = json_decode($credentials, false); if (!$this->isValidCredentials($decodedCredentials)) { return null; } $credential = new ...
CoderJoe's user avatar
0 votes
1 answer
113 views

I want to configure phpstan such that it reports use of undefined method calls <?php namespace App; class Testeroni { public function asdf() { $this->iDoNotExist(); // Ok ...
Brucie Alpha's user avatar
  • 1,246
0 votes
1 answer
279 views

I am currently upgrading a project to use phpstan to better catch type errors, @template and class-string have been particularly helpfull However, I have a method on the projects router, that takes ...
Steve's user avatar
  • 20.5k
0 votes
1 answer
976 views

I am a novice in PHP and I am working on a legacy project where I am trying to upgrade PHP with Version 8.2 + ubuntu environment. The PHP code is written in ZEND Framework. The legacy code is written ...
Ash_and_Perl's user avatar
0 votes
1 answer
269 views

I am using swagger to create an OpenApi documentation. I am switching now to php attributes and phpstan in level 6 complain about missing specific array declaration, which worked totally fine as long ...
Calamity Jane's user avatar
2 votes
1 answer
210 views

readonly class Identifier extends Regexp { /** * @param array<int,int>|array<int,string> $possibleValues */ public function __construct(array $possibleValues = []) { ...
Floxblah's user avatar
  • 234
0 votes
1 answer
2k views

When using php type declarations, PHPStan seems to think that I should specify the array members in both the PHPDoc as well as the actual declaration, but correct me if I'm wrong PHP (at least PHP 7) ...
Aayla Secura's user avatar
1 vote
1 answer
160 views

I am using laravel 11 + phpstan for the quality code. In this method : /** * @param array<string> $request * @return LengthAwarePaginator<App\Models\User> */ public ...
Dom's user avatar
  • 3,506
0 votes
1 answer
815 views

In laravel 11 with larastan/larastan 2.9 app I with request : $managers = ModelHasPermission ::getByPermissionId(PERMISSION_APP_MANAGER) ->with('user') // ERROR POINTING THIS LINE 37 -&...
mstdmstd's user avatar
  • 3,309
0 votes
0 answers
40 views

I have some method with generic: /** * @param class-string<T> $class * @return T * @throws ClientException * * @template T */ private function doSomething(string $content, string $class): ...
sveta600's user avatar
  • 537
0 votes
2 answers
571 views

Background I do have classes (here: ClassA and ClassB) that shall be tested. As these classes are similar, I created an abstract test-class that implements an interface. Problem At level 7, PhpStan is ...
Tim K.'s user avatar
  • 378
-1 votes
2 answers
2k views

TL;DR: I see 'phpstan/extension-installer: Extensions installed' message but phpstan act like if it wasn't. In an existing project, I want to add phpstan with symfony & doctrine extension. When I ...
Asenar's user avatar
  • 7,086
0 votes
0 answers
338 views

I created a .neon file from the documentation. https://phpstan.org/user-guide/discovering-symbols I put the .neon file in the project root folder where I am running the phpstan command from. I added ...
user1794918's user avatar
  • 1,181
1 vote
1 answer
112 views

I'm using generics to type hint some classes and interfaces in php/phpstan. What i want to achieve is that a function returns a an interface object but with generic hinting: class Car { } /** * @...
dr0bz's user avatar
  • 484
-2 votes
1 answer
756 views

I am using the devspaces tool as part of a project with a few dozen developers. It's great, but in order to make certain things work locally in my IDE, I still run Composer on my local machine ...
Viscountess of the Junkyard's user avatar
0 votes
2 answers
332 views

In Symfony, if you want to autowire some dependencies in a service, many times you use an interface instead of a concrete class. For example, you might have: public function __construct( ...
Carlos Granados's user avatar
0 votes
1 answer
619 views

In CakePHP; the ORM supports an SQL function abstraction layer; so you can use functions like "SUM" and "MAX". These functions are defined in the FunctionBuilder. Cake also lets ...
user4681670's user avatar
0 votes
1 answer
492 views

Is there a way to document an array, where every key is a string and every item is an object of specific types? I tried this @param array{string, MyObj} $accounts but apparently Phpstan thinks of it ...
Majesty's user avatar
  • 2,089
1 vote
3 answers
2k views

I have two interfaces (ClienInterface, ClientFactoryInterface) and two classes implementing them (ConcreteClient, ConcreteApiClientFactory). ConcreteClient has method not definded in ClienInterface. ...
piotr85's user avatar
  • 13
0 votes
2 answers
302 views

I'm trying to write a custom phpstan rule to not allow other devs to call Cart::save() ($cart->save()) from everywhere in the codebase, but to call only from CartRepository, and if it's called ...
Bogdan  Dubyk's user avatar
  • 5,644
0 votes
1 answer
636 views

I feel stupid asking such a simple question, but I am clearly missing something basic. The CollectionOrdered class below is meant to "carry a payload" and the point of HasPayloadInterface is ...
Doug Wilbourne's user avatar
0 votes
1 answer
560 views

I'm using larastan on a Laravel project. When I use a facade like \Auth::check() like code below, larastan can't resolve the return type of this method. function index() { if(\Auth::check()) { // as ...
Natsuki's user avatar
  • 21
0 votes
1 answer
942 views

I have a PHP project which is a library for trees / nodes. It has several generic objects, all of which work in parallel - they are either ordered or unordered, depending on whether the children of a ...
Doug Wilbourne's user avatar

1
2 3 4 5