auto-fix "Call to function in_array() requires parameter #3 to be set/true."

Đang mở
#347 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@staabm đang làm issue này rồi.

Từ ngày 4/11/2026.

  • #349 của @staabm — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
php
Lĩnh vực
testing, tooling

Hướng nghiên cứu

Read the linked pull request #349 first; it already has this issue in progress. The issue describes the fixer behavior for in_array(), array_search() and eligible array_keys() calls, including named arguments, splat calls, and types inferred from PHPDoc. Done means only calls whose strict equivalence can be proven are changed, while base64_decode() and array_keys() calls without a search value remain unaffected.

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

Mô tả

if we know native haystack and needle types for a in_array, array_keys or array_search call, it would be great we could fix add a true as 3rd parameter in case its missing or can always be true. we should only fix when haystacks' iterable type is a super type of needle (strict comparison). the fixer must not change calls where equivalence cannot be proven.

Example: in_array($needle, X::VALS) into its strict counterpart in_array($needle, X::VALS, true).
https://phpstan.org/r/e288cf2a-08e5-4c06-9255-1a98eefc99fe

named arguments should be supported and calls using the splat operator should be skipped.

we should not fix calls which get their iterable-value type from a phpdoc, e.g.:

/** @return int[] */ 
function getArray(): array {}

function doFoo(int $i):bool {
  return in_array($i, getArray());
}

For array_keys(), only consider calls with at least two arguments, since the strictness flag matters only when a search value is supplied. Calls without a search value should remain unchanged.

The rule also reports calls to other functions, such as base64_decode(). Those calls should not be made fixable by this change.

Ngôn ngữ chính
PHP
Star
714
Fork
63
Merge trung bình
1 ngày 11 giờ
Pull request đã merge (30 ngày)
8

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

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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 phpstan/phpstan-strict-rules

Tất cả issue của phpstan/phpstan-strict-rules

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.