MergePhpstanDocTagIntoNativeRector and RemoveUselessReturnTagRector removes return type that adds a clarification

Đã đóng
#9,952 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Một pull request liên quan đã được merge.

  • #8924 của @APX403 — đã merge

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
devtools

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
PHP
Star
10.5k
Fork
742
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rectorphp/rector

Tất cả issue của rectorphp/rector

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.