MergePhpstanDocTagIntoNativeRector and RemoveUselessReturnTagRector removes return type that adds a clarification

Fermée
#9,952 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Une pull request liée a déjà été fusionnée.

  • #8924 par @APX403 — fusionnée

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
45/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
php
Domaine
devtools

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
PHP
Étoiles
10.5k
Forks
742
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de rectorphp/rector

Toutes les issues de rectorphp/rector

Issues similaires

Plus d'issues PHP

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.