225 questions
1
vote
0
answers
122
views
How to typehint this Generator?
My data provider is sending arrays. The first element is always a string, the second one an array of Token.
public static function dataProvider(): Generator
{
yield ['15', [new Token(15, Lexer::...
0
votes
2
answers
530
views
PHPStan error - Parameter #1 $url of method Illuminate\Http\Client\PendingRequest::get() expects string, string|null given - how to remedy this?
I am using PHPStan for static analysis on a PHP application, I have this set quite high which can be problematic at times and i'm getting the following error.
public function generate(GetFileData $...
1
vote
1
answer
473
views
PHP: Phpstan class_implements call interface method: Call to an undefined method
I have a method in an abstract parent class. The behaviour basically depends on wether the child class inherits an interface or not.
How can I make phpstan recognize this conditional (in this case &...
4
votes
2
answers
371
views
Seeking Guidance on PHPStan Configuration for Legacy Code Migration - "Variable $... might not be defined"
I am currently in the process of migrating a large, super-legacy codebase to PHP 8.x, and I am utilizing PHPStan to identify potential issues. However, I have encountered a challenge related to the ...
0
votes
1
answer
336
views
PHPStan error - Property App\Models\Report::$succeeded_at (Carbon\Carbon|null) does not accept int|null
I am using PHPStan within a Laravel 10 app and have set this to quite a high level (good practice I guess) - I have run into a few errors and i'm trying to figure out the best way to resolve them.
---...
1
vote
1
answer
965
views
PHPStan reporting "extends unknown class" for a core CakePHP feature
I have a web application which is running on CakePHP 4.4.4
I have recently started using PHPStan with the codebase running at level 1. This level is specified in our configuration file, phpstan.neon
...
3
votes
4
answers
4k
views
Trying to fix PHPStan Issues with Laravel's MorphTo relations and Model properties
We recently started using PHPStan 1.10 at level 6 in a Laravel 10 PHP 8.2 project.
It reports a few remaining issues in the following model that I would like to fix.
class ArticlePrice extends Model
{
...
0
votes
1
answer
166
views
What is the type of the handle given back by fopen()? [duplicate]
I have this code:
class CsvWriter
{
private $handle;
public function openToFile($filePath): void
{
$this->handle = fopen($filePath, 'wb+');
if (false === $this->...
0
votes
1
answer
245
views
How to fix Access to an undefined property error in laravel-validated-dto class?
On laravel 10 site I added with wendelladriel/laravel-validated-dto package app/DTO/ItemsFilterDTO.php class
with methods :
<?php
namespace App\DTO;
use WendellAdriel\ValidatedDTO\Casting\...
-1
votes
1
answer
400
views
How to avoid any phpstan errors with try / catch block in the end of the function?
On laravel 10 site running phpstan on method
/**
* Retrieve user getItemss related to getItems by $itemId
*
* param int $itemId - getItems id
*
* @return JsonResponse with ...
1
vote
1
answer
643
views
PHPStan does can not found functions in CodeIgniter 4
I have an CodeIgniter 4 application, and I am using PHPStan to help me with static analysis. My problem is that PHPStan complain that he can not find the CodeIgniter 4 functions. I check the PHPStan ...
0
votes
0
answers
27
views
Laravel Sort by column in related table [duplicate]
I am asking if there is a way to sort by a second-order table without triggering the static analysis.
I have several related tables and I'm trying to sort the results by a related column. For my ...
-2
votes
2
answers
374
views
Why larastan raise errors on array parameter definitions?
After I set in phpstan.neon parameter :
level: 7
I got errors :
30 Method App\Rules\ItemModelRules::getValidationRulesArray() has parameter $skipFieldsArray with no value type specified in ...
1
vote
1
answer
2k
views
phpstan: Template type only for return type
I think I am misunderstanding something about phpstan.
I have the following method in my interface:
/**
* @phpstan-template T of Searchable
*
* @param string $...
1
vote
1
answer
612
views
PHPStan and PHPMD outputs missing in GitHub Actions but present locally
I'm running PHPStan and PHPMD in my GitHub Actions workflow. Locally, both tools return a list of issues, but in GitHub Actions, no issues are reported. I've made sure the path is right in github ...
1
vote
1
answer
236
views
How to I can tune JUnit report from PHPStan for GitLab CI?
We have a box version of GitLab, where we want to use PHPStan and show test results in CI. For a better user experience, I want to convert the PHPStan JUnit report via sed command. But there are two ...
1
vote
1
answer
740
views
How to make PHPStan understand a function asserts the existence of an array key
PHPStan can recognise we check if array key exists:
<?php declare(strict_types = 1);
/** @return array<mixed> */
function returnMixedArray(): array {
return [];
}
/**
* @return array{
...
-2
votes
1
answer
1k
views
force ignore line larastan-phpstan
i´m getting this error when i´m doing scann in my proyect:
Class App\Jobs\ProcessCalculoGrupo uses unknown trait App\Fabricas\SidraExtraccionTrait.
💡 Learn more at https://phpstan.org/user-...
0
votes
0
answers
661
views
Access to an undefined property trait larastan
I´m trying to solve errors in my proyect with larastan. One error that this library, returned it´s: Access to an undefined property App\Cargador\Prevalidaciones\PrevalidarCodificacionUTF8::$tarea
...
0
votes
1
answer
553
views
phpstan : discovering symbols with scanFiles and scanDirectories
I'm using phpstan 1.10.41 and get this error
------ ---------------------------------------------------------------------
Line lib/src/fpdf17/fpdf.php
----...
1
vote
1
answer
2k
views
How to run PHPStan in PhpStorm on Windows through WSL?
I run PhpStorm 2023.1 on Windows 11. On the Windows machine, I have an Ubuntu WSL enabled, so that I can develop a PHP project, which works fine.
Now I wanted to enable PHPStan support yet I get the ...
1
vote
0
answers
163
views
exception for callable in phpstan
how can I describe the exceptions thrown from callable in phpDoc?
For example I have:
/**
* @param callable(int): bool
*/
function (callable $foo, int $number): ?bool
{
try {
return $foo(...
0
votes
1
answer
149
views
How to determine if a node is inside certain class constructor in PHPStan
I want to determine whether a MethodCall node is inside a certain class constructor. More specifically, I want to know if a method is being called within an exception constructor.
This is the ...
0
votes
1
answer
364
views
How to determine whether a method argument is a literal/scalar string in PHPStan, even if concatenated
I want to determine whether a given method argument is a string. I thought I had a pretty good solution (below), but it turns out not to handle some important edge cases--namely concatenated strings, ...
2
votes
1
answer
3k
views
Can not run phpstan under docker with memory lack error
I try to run phpstan(nunomaduro/larastan 2.6.3) under docker (based on php:8.1.6-apache) in laravel 10.8 app and got memory lack error.
I added memory limit in console command, but error anyway :
root@...
1
vote
1
answer
1k
views
Access to an undefined property phpstan laravel 10
I´m trying to solve problems in my proyect. I have this message:
Access to an undefined property
Illuminate\Database\Eloquent\Model::$bloqueante. ...
0
votes
1
answer
389
views
PHPStan starts complaining only when I am more strict about type
I tried the following code with level 9 PHPStan:
<?php declare(strict_types = 1);
class Foo
{
/** @param array<array<mixed>> $bar */
public function foo ($bar) : void {
...
1
vote
0
answers
1k
views
phpstan array shape definition using a class constant
Is there a way to use class constants to define array shapes in phpstan?
The purpose is to enable the definition to be used by PHP code, otherwise we have to repeat the definition (once for phpstan ...
1
vote
0
answers
147
views
PHPstan has problems finding a method
We use our own OAuth authentication. Now I get the following problem:
Call to an undefined method Laravel\Socialite\Two\ProviderInterface::addUserRequestParam().
with PHPstan with this code:
/**
...
1
vote
0
answers
358
views
Phpstan function doc callable and parameters
Is there any way to pass parameters in doc from callable to function baz $params?
I need give parameters in array associated by its names.
interface Bar {
/**
* @template TResult of mixed
...
1
vote
1
answer
4k
views
php error Call to an undefined static method with PHPStan
I have phpstan in my proyect to analyze all my code. I´m working with laravel and php 8.2.
My problem it´s that when i execute phpStan return any errors and i have one in my function that i´m calling ...
1
vote
1
answer
766
views
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 ...
1
vote
1
answer
842
views
Yii2 + phpstan?
I have a project (PHP 8.2.6, Yii2, PHPStan). After running phpstan command, I got a list of errors that should be fixed for successful checking. Example of errors:
Access to an undefined property yii\...
0
votes
1
answer
1k
views
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
------ ---------...
0
votes
0
answers
110
views
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 ...
0
votes
2
answers
119
views
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 ...
6
votes
5
answers
5k
views
Larastan complains about collection methods paramaters after upgrading to Laravel 10
After upgrading to Laravel 10 I'm having hard times with Larastan errors.
The following code which was perfectly fine until 1 hour ago:
return $this->articleRepository->getDefaultArticles($...
3
votes
1
answer
2k
views
PHPstan Cannot access property $children on App\Account|null
when I run PHPstan at level 8, I get for example with this code:
/**
* @return Collection<int, Account>
*/
public function getCustomersAttribute(): Collection
{
return $...
0
votes
1
answer
274
views
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 ...
3
votes
0
answers
245
views
How to pass this rule with larastan?
I am using Laravel 10 + larastan to inspect my code, at level 9 (maximum).
I have this error :
Access to an undefined property App\Models\User::$full_name.
The code is :
$model->created_by = Auth::...
0
votes
1
answer
382
views
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\...
0
votes
1
answer
165
views
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 ...
0
votes
2
answers
110
views
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 ...
3
votes
1
answer
989
views
How to tell PHP static code analysers to read the generic type hint from a callable, instead of expecting the class name as a string?
I'm trying to remove some code duplication that has proven to be prone to human errors.
I created a working sample code at https://3v4l.org/QFA6m#v8.2.7 and a demo of PHPStan failing where expected, ...
0
votes
1
answer
1k
views
PHPStan errors on Laravel Model relationships, any solutions?
PHPStan has found hundreds of errors in the Laravel project. Mostly, Access to an undefined property Illuminate\Database\Eloquent\Model::$id.
for constructs like
$project_id = $checkpoint->project-&...
0
votes
1
answer
1k
views
Phpstan analysis fails as part of the Gitlab pipeline
Phpstan analysis fails when I run it as part of the Gitlab pipeline, it passes locally. I'm talking about the analysis and not the running of the command itself. I do not get 'command not found' or '...
0
votes
1
answer
774
views
Does PhpStan and Psalm measures cyclomatic complexity?
I've read the documentation from PhpStan and Psalm, and i couldn't find the rules where it checks the Cyclomatic Complexity like Phpmd does here
Also, is it possible to cusomise rules within levels ...
0
votes
3
answers
163
views
How to write a rule to pass the Larastan test
I'm struggling with the return code of a validation rule to pass the "Larastan" test.
The code for this rule is:
public function rules(): array
{
return [
'name' => [
...
1
vote
0
answers
204
views
How to reach level 8 with larastan?
I'm trying to have super clean laravel code using larastan.
For the moment it is flawless up to level 7 (out of 9 possible). And I get stuck by going to 8 on this code:
$user = User::where('email', $...
4
votes
1
answer
6k
views
PHPStan error: Method should return specific types but returns mixed
I'm using PHPStan for static analysis in my PHP 8.4.2 project, and I'm encountering an issue with a class method that returns multiple types or null. Here's my method with type hints and PHPDoc ...