Phpstan-bỏ qua

Xin lưu ý rằng một số lỗi nghiêm trọng đã chọn (như sự cố tự động tải, không tìm thấy lớp cha, lỗi phân tích cú pháp, v.v. ) không thể bỏ qua và phải được giải quyết để không có lỗi khi chạy PHPStan

Bỏ qua mã bằng PHPDocs

Lỗi có thể được bỏ qua bên cạnh dòng mã vi phạm bằng cách sử dụng thẻ PHPDoc trong nhận xét

  • @phpstan-ignore-line
  • parameters:
    reportUnmatchedIgnoredErrors: false0

Có thể sử dụng tất cả các kiểu nhận xét PHP (parameters:
reportUnmatchedIgnoredErrors: false1, parameters:
reportUnmatchedIgnoredErrors: false2, parameters:
reportUnmatchedIgnoredErrors: false3)

Bỏ qua trong tập tin cấu hình

Có thể bỏ qua lỗi bằng cách thêm biểu thức chính quy vào tệp cấu hình bên dưới khóa parameters:
reportUnmatchedIgnoredErrors: false4. Để bỏ qua một lỗi bởi một biểu thức chính quy trong toàn bộ dự án, hãy thêm một mục nhập chuỗi

parameters:
ignoreErrors:
- '#Call to an undefined method [a-zA-Z0-9\\_]+::doFoo\(\)#'
- '#Call to an undefined method [a-zA-Z0-9\\_]+::doBar\(\)#'

Để bỏ qua các lỗi chỉ bằng một biểu thức chính quy trong một tệp cụ thể, hãy thêm một mục nhập bằng các phím parameters:
reportUnmatchedIgnoredErrors: false5 hoặc parameters:
reportUnmatchedIgnoredErrors: false6 và parameters:
reportUnmatchedIgnoredErrors: false7 hoặc ________0____8. Các mẫu ký tự đại diện tương thích với PHP parameters:
reportUnmatchedIgnoredErrors: false9 cũng được hỗ trợ. Bạn có thể chỉ định số lần dự kiến ​​xảy ra lỗi bằng cách sử dụng parameters:
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- '#This message will not be reported as unmatched#'
- '#This message will not be reported as unmatched either#'
-
message: '#But this one will be reported#'
reportUnmatched: true0 (tùy chọn, chỉ áp dụng cho parameters:
reportUnmatchedIgnoredErrors: false5 chứ không phải parameters:
reportUnmatchedIgnoredErrors: false6 và parameters:
reportUnmatchedIgnoredErrors: false7, không phải parameters:
reportUnmatchedIgnoredErrors: false8)

Các đường dẫn tương đối trong khóa parameters:
reportUnmatchedIgnoredErrors: false7 và parameters:
reportUnmatchedIgnoredErrors: false8 được giải quyết dựa trên thư mục của tệp cấu hình nằm trong. Vì vậy, nếu parameters:
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- '#This message will not be reported as unmatched#'
- '#This message will not be reported as unmatched either#'
-
message: '#But this one will be reported#'
reportUnmatched: true7 của bạn nằm trong thư mục gốc của dự án và bạn muốn bỏ qua một lỗi trong parameters:
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- '#This message will not be reported as unmatched#'
- '#This message will not be reported as unmatched either#'
-
message: '#But this one will be reported#'
reportUnmatched: true8, khóa đường dẫn của bạn có thể đơn giản là parameters:
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- '#This message will not be reported as unmatched#'
- '#This message will not be reported as unmatched either#'
-
message: '#But this one will be reported#'
reportUnmatched: true8

Sử dụng các trường bên dưới, bạn có thể tạo một mục nhập mà bạn có thể đặt vào phần parameters:
reportUnmatchedIgnoredErrors: true
ignoreErrors:
- '#This message will be reported as unmatched#'
- '#This message will be reported as unmatched too#'
-
message: '#But this one will not be reported#'
reportUnmatched: false0 trong tệp cấu hình của mình. Nó đề cập đến sự phức tạp của việc viết một biểu thức chính quy phù hợp từ một chuỗi đơn giản và mã hóa biểu thức chính quy đó thành định dạng neon

Sao chép phần sau vào phpstan của bạn. đèn neon

Đã xảy ra lỗi. Vui lòng thử lại sau

đường cơ sở

Nếu bạn muốn bỏ qua tất cả các lỗi hiện tại và chỉ tập trung vào mã mới và mã đã thay đổi kể từ bây giờ, hãy đi và tìm hiểu về tính năng cơ bản

Nếu một số lỗi bị bỏ qua (cả từ cấu hình và PHPDocs) không xuất hiện trong kết quả nữa, PHPStan sẽ cho bạn biết và bạn sẽ phải xóa mẫu khỏi cấu hình. Bạn có thể tắt hành vi này bằng cách đặt parameters:
reportUnmatchedIgnoredErrors: true
ignoreErrors:
- '#This message will be reported as unmatched#'
- '#This message will be reported as unmatched too#'
-
message: '#But this one will not be reported#'
reportUnmatched: false1 thành parameters:
reportUnmatchedIgnoredErrors: true
ignoreErrors:
- '#This message will be reported as unmatched#'
- '#This message will be reported as unmatched too#'
-
message: '#But this one will not be reported#'
reportUnmatched: false2 trong cấu hình

parameters:
reportUnmatchedIgnoredErrors: false

Bạn có thể bật/tắt báo cáo bỏ qua không sử dụng một cách rõ ràng cho mỗi mục trong parameters:
reportUnmatchedIgnoredErrors: true
ignoreErrors:
- '#This message will be reported as unmatched#'
- '#This message will be reported as unmatched too#'
-
message: '#But this one will not be reported#'
reportUnmatched: false3. Điều này ghi đè cài đặt parameters:
reportUnmatchedIgnoredErrors: true
ignoreErrors:
- '#This message will be reported as unmatched#'
- '#This message will be reported as unmatched too#'
-
message: '#But this one will not be reported#'
reportUnmatched: false1 toàn cầu

parameters:
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- '#This message will not be reported as unmatched#'
- '#This message will not be reported as unmatched either#'
-
message: '#But this one will be reported#'
reportUnmatched: trueparameters:
reportUnmatchedIgnoredErrors: true
ignoreErrors:
- '#This message will be reported as unmatched#'
- '#This message will be reported as unmatched too#'
-
message: '#But this one will not be reported#'
reportUnmatched: false

Loại trừ toàn bộ tệp

Nếu cơ sở mã của bạn chứa một số tệp cố ý bị hỏng (e. g. để kiểm tra hành vi của ứng dụng của bạn trên các tệp có mã PHP không hợp lệ), bạn có thể loại trừ chúng bằng cách sử dụng khóa parameters:
reportUnmatchedIgnoredErrors: true
ignoreErrors:
- '#This message will be reported as unmatched#'
- '#This message will be reported as unmatched too#'
-
message: '#But this one will not be reported#'
reportUnmatched: false5. Mỗi mục nhập được sử dụng làm mẫu cho hàm parameters:
reportUnmatchedIgnoredErrors: false9

parameters:
excludePaths:
- tests/*/data/*

Đây là một phím tắt cho

parameters:
excludePaths:
analyseAndScan:
- tests/*/data/*

Nếu cấu trúc thư mục dự án của bạn kết hợp mã của riêng bạn (mã bạn muốn phân tích và sửa lỗi) và mã của bên thứ ba (mà bạn đang sử dụng để khám phá các ký hiệu nhưng không muốn phân tích), thì cấu trúc tệp có thể giống như

├── phpstan.neon └── src ├── foo.php ├── ... └── thirdparty └── bar.php

Trong trường hợp này, bạn muốn phân tích toàn bộ thư mục parameters:
reportUnmatchedIgnoredErrors: true
ignoreErrors:
- '#This message will be reported as unmatched#'
- '#This message will be reported as unmatched too#'
-
message: '#But this one will not be reported#'
reportUnmatched: false7, nhưng muốn loại trừ parameters:
reportUnmatchedIgnoredErrors: true
ignoreErrors:
- '#This message will be reported as unmatched#'
- '#This message will be reported as unmatched too#'
-
message: '#But this one will not be reported#'
reportUnmatched: false8 khỏi quá trình phân tích. Đây là cách cấu hình PHPStan

parameters:
paths:
- src
excludePaths:
analyse:
- src/thirdparty

Ngoài ra, có thể có một thư mục parameters:
reportUnmatchedIgnoredErrors: true
ignoreErrors:
- '#This message will be reported as unmatched#'
- '#This message will be reported as unmatched too#'
-
message: '#But this one will not be reported#'
reportUnmatched: false9 chứa các tệp mà bạn không muốn phân tích cũng như không muốn sử dụng để khám phá các biểu tượng. Bạn có thể sửa đổi cấu hình để đạt được hiệu ứng đó

Chủ đề