MergePhpstanDocTagIntoNativeRector and RemoveUselessReturnTagRector removes return type that adds a clarification

Abierto
#9,952 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
php
Área
devtools

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
PHP
Estrellas
10.5k
Forks
742
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rectorphp/rector

Todos los issues de rectorphp/rector

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.