[英]Proper type hinting for IteratorAggregate satisfying Psalm and PhpStorm
我有 collections 使用IteratorAggregate接口。 而且我找不到一種方法來正確地提示 Psalm 和 PhpStorm 都滿意。 這是一個簡化的例子。 它有一個AbstractCollection和一個Collection ,但實際上有多個 collections 擴展了Ab ...
[英]Proper type hinting for IteratorAggregate satisfying Psalm and PhpStorm
我有 collections 使用IteratorAggregate接口。 而且我找不到一種方法來正確地提示 Psalm 和 PhpStorm 都滿意。 這是一個簡化的例子。 它有一個AbstractCollection和一個Collection ,但實際上有多個 collections 擴展了Ab ...
[英]How to resolve Pslam MixedReturnTypeCoersion
我在 symfony 項目中運行 psalm 並收到上述錯誤,下面是方法定義,但我不知道要調整什么以修復錯誤。 ...
[英]UnitEnum cannot be cast to string
我在 config/services.yaml 中聲明了一個變量 我在我的 controller 中訪問它,如下所示: 一切正常,但psalm給出以下錯誤: 有什么建議,請問如何解決? 復制了pslam-plugin-symfony官方github issue中的問題: https://github ...
[英]phpstan and psalm ail because of an unidentifiable problem
對於 php 項目,有一段時間我的 phpstan 和 psalm 測試失敗,錯誤消息不清楚。 我試圖調試,重建提交,但沒有成功。 我無法理解。 這些是output 、 composer.json和ci.yml 。 我可以發現這些線條。 對於psalm : Uncaught Error: Ca ...
[英]Laravel Factory Generics With Psalm
我正在努力讓通用的 Laravel 9 工廠與 psalm 一起工作。 文檔塊: 用例: 錯誤: InvalidTemplateParam - app/Domains/Trips/Seeders/TripSeeder.php:23:9 - Extended template param TModel ...
[英]PHP, Static Analysis, and Recursive Type Checking
我正在查看一個使用數組來定義 WHERE 子句的數據庫 ORM,例如 $articles->find('all', [ 'OR' => [ 'category_id IS NULL', 'category_id' => $id, ], ] ...
[英]defining generic return for a method/function in php with phpdocblock
有沒有辦法指定 function 將返回特定類型的 object,其中類型是其中一個參數的字符串? 例如/** * @return object<$class> */ public function create(string $class): object { ... some ...
[英]How to tell psalm to save getter state if property wasn't modified before the further checks?
對於此代碼片段,psalm 將返回類似PossiblyNullOperand或類似的錯誤。 我知道這是一種預期的行為,可以像這樣修復: 但是在 psalm 中是否有一個配置參數,它會忽略這些錯誤,比如 getter 總是返回相同的結果? 詩篇版本:4.18.x ...
[英]Is there a way to correctly use sanitize_text_field and wp_unslash that doesn't cause psalm to error with "expects string, possibly different type"
我正在編寫一個 WordPress 插件,並且需要正確地取消斜線並清理 PHP 中的變量。 我使用 psalm 作為我的 static 分析工具,它將我的代碼識別為包含潛在錯誤: 詩篇顯示這是一個錯誤(或警告,取決於我設置的詩篇級別): 我已經嘗試了各種其他方式來安排上面的代碼,以防止 psalm ...
[英]PHPDoc & Psalm - Annotate an "array of classes"
在我的代碼中,我創建了一個這樣的 EventFactory: PostCreatedEvent和ExerciseExecutedEvent都擴展了一個抽象的 class Event 。 你能告訴我是否有辦法以不從 Psalm 接收錯誤的方式注釋數組? ...
[英]In PHP how do I type hint an instance of a class accessed using a string as the class name
使用 Laravel,我正在遍歷一系列類並對每個 class 的實例子集進行操作。 這些類以字符串形式提供,例如:$c = '\App\Models\Book'; $c::each(function($i) { echo $i->title . PHP_EOL; }); 我將如何輸 ...
[英]Psalm check for calls to "die"
有沒有辦法配置 Psalm 調用die或exit導致錯誤? 我對大量使用這兩個命令的代碼庫有問題,並且希望至少避免人們添加不應該存在的新 die 命令。 ...
[英]How to make Psalm recognize variables from an included file
我有一個包含在 function 中的配置文件,如下所示:function getConnection() { include 'config.php'; return new Connection($config['host']); } 問題是讓 Psalm 從配置文件中識別$confi ...
[英]Pagerfanta template causing error in psalm
我正在嘗試從 phpdoc 遷移到 psalm,但基於模板的返回出現奇怪的錯誤。class Message {} interface FooInterface { /** @return Pagerfanta|Message[] */ public function getMess ...
[英]How to annotate Laravel Collection elements during iteration
我在考慮如何在 PhpStorm 中注釋類型。 我相信 PhpStorm 正在使用 Psalm 來解析類型,但我無法在此處找到如何注釋類型以獲取建議: 我的應用程序中的$row將始終是Collection object,我想在此處的某處用注釋標記它。 有誰知道如何做到這一點? /** ...
[英]Php psalm configuration and syntax error reporting
我有一個簡單的語法錯誤的案例。 它是這樣的 所以,在 param $c 之后有一個語法錯誤——一個多余的逗號(我使用的是 php7.3)。 當我運行./vendor/bin/psalm src/Foo.php --no-cache它顯示這里沒有任何損壞。 我的問題是我是否缺少一些配置或其他東西 ...
[英]Extend a generic of an interface using psalm
我已經習慣使用 psalm,但我遇到了一個問題。 我已經在 C# 中有這個結構,它對我有用。 我真的不明白如何使用 psalm 解決這個問題。 我有一個ContextInterface和另一個實現它。interface ContextInterface { public function getPr ...
[英]Psalm reports InvalidArrayOffset, but the value will be within bounds
在這個簡單的“隨機字符串”生成器上運行 Psalm 時: 我收到一個錯誤(如此處所示): 錯誤:InvalidArrayOffset - 15:11 - 無法使用 int 偏移訪問變量 $numbers 上的值,期望 -8|-7|-6|-5|-4|-3|-2|-1|0|1|2 |3|4|5|6|7 ...
[英]Psalm: How to handle dedicated view files?
我的設置包括一個帶有類的lib文件夾和一個帶有 PHP 文件的view文件夾,這些文件產生 output。 視圖導入到View class 中,類似於:class View { public function render(string $basename, Array $params) ...
[英]How To Declare Traversable Type?
PHP 中有多種類型提示,現在在 PHP 8 中有更多類型提示,在 Psalm 中甚至更多。 但是聲明類型而不是暗示預期的類型呢? 我有一個interface Collection extends Traversable ,我需要聲明它是Abc類型的可遍歷。 我怎樣才能做到這一點,以便 PHPD ...