MergePhpstanDocTagIntoNativeRector and RemoveUselessReturnTagRector removes return type that adds a clarification

クローズ
#9,952 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

関連するプルリクエストがすでにマージされています。

  • #8924 @APX403 による — マージ済み

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php
領域
devtools

調査の方向性

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

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 はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rectorphp/rector のほかの issue

rectorphp/rector の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。