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 PHPDocsLỗ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 Có thể sử dụng tất cả các kiểu nhận xét PHP ( parameters: reportUnmatchedIgnoredErrors: false 1, parameters: reportUnmatchedIgnoredErrors: false 2, parameters: reportUnmatchedIgnoredErrors: false 3)Bỏ qua trong tập tin cấu hìnhCó 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: false 4. Để 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ỗiparameters: 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: false 5 hoặc parameters: reportUnmatchedIgnoredErrors: false 6 và parameters: reportUnmatchedIgnoredErrors: false 7 hoặc ________0____8. Các mẫu ký tự đại diện tương thích với PHP parameters: reportUnmatchedIgnoredErrors: false 9 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: true 0 (tùy chọn, chỉ áp dụng cho parameters: reportUnmatchedIgnoredErrors: false 5 chứ không phải parameters: reportUnmatchedIgnoredErrors: false 6 và parameters: reportUnmatchedIgnoredErrors: false 7, không phải parameters: reportUnmatchedIgnoredErrors: false 8)Các đường dẫn tương đối trong khóa parameters: reportUnmatchedIgnoredErrors: false 7 và parameters: reportUnmatchedIgnoredErrors: false 8 đượ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: true 7 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: true 8, 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: true 8Sử 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: false 0 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 neonSao 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: false 1 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: false 2 trong cấu hìnhparameters: 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: false 3. Đ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: false 1 toàn cầuparameters: 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: true
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: false
Loại trừ toàn bộ tệpNế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: false 5. Mỗi mục nhập được sử dụng làm mẫu cho hàm parameters: reportUnmatchedIgnoredErrors: false 9parameters: 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: false 7, 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: false 8 khỏi quá trình phân tích. Đây là cách cấu hình PHPStanparameters: 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: false 9 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 đó |