MergePhpstanDocTagIntoNativeRector and RemoveUselessReturnTagRector removes return type that adds a clarification
関連するプルリクエストがすでにマージされています。
- #8924 @APX403 による — マージ済み
評価
調査の方向性
The bug is in the rules RemoveUselessReturnTagRector and MergePhpstanDocTagIntoNativeRector, which wrongly drop a conditional @phpstan-return tag on isListOfArrays. Start with the existing test fixtures for these two rules and add the reported method as a case where the tag must stay. Done when the snippet keeps its @phpstan-return tag and the rule tests pass.
索引モデルが issue の本文から書いたものです。
説明
Bug Report
| Subject | Details |
|---|---|
| Rector version | 2.8.3 |
The @phpstan-return that narrows down the return type of isListOfArrays gets wrongfully removed. Code that uses $data[0] after isListOfArrays now throws a PHPStan error: expects array<mixed>, mixed given.
Minimal PHP Code Causing Issue
/**
* @param array<mixed> $data
*
* @phpstan-return ($data is list<array> ? true : false)
*/
private function isListOfArrays(array $data): bool
{
return \array_is_list($data) && \array_all($data, static fn (mixed $item): bool => \is_array($item));
}
https://getrector.com/demo/bb2e87cf-253d-4aed-9bc4-25a4a6b2f6a0
Expected Behaviour
Do not remove the return type.
EDIT: Claude told me to use @phpstan-assert-if-true list<array<mixed>> $data instead, which doesn't get removed by rector.
- 主要言語
- PHP
- スター
- 10.5k
- フォーク
- 742
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rectorphp/rector のほかの issue
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
MyCLabsMethodCallToEnumConstRector should only refactor according to RuleDefinition対応中かも @samsonasik が 2 日前に担当しました。 オープンbug
難易度 3/5 半日 初心者へのやさしさ 55/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
rectorphp/rector の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
Author mapping step: "create new user" and "assign to existing user" fields have no spacing between them対応中かも @umeshnevase が今日担当しました。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
WordPress/wordpress-importer#275 ·
-
security/openvpn-legacy: read-only user can stop a running VPN対応中かも @besendorf が今日担当しました。 オープンincomplete
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
opnsense/plugins#5887 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
jira-created
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
-
No Code Attached Yet
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
joomla/joomla-cms#48786 ·
メンテナーはふだん 1 日以内に返信