PHPErrorReportingSniff flags debug constants used as values in const declarations
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- Nửa ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Read check_const_declaration() in phpcs-sniffs/PluginCheck/Sniffs/CodeAnalysis/PHPErrorReportingSniff.php, which currently reports any matching T_STRING between const and ;. The fix needs to distinguish the declared name from value reads, and to skip class/interface/trait/enum bodies and namespaced code, using the PHPCS token scope and namespace helpers already used elsewhere in the sniff set. Extend the sniff's unit test file with the cases listed (value reads, array() multi-const, class, namespace) and run that test plus the reproduction command printf '<?php\nconst FOO = WP_DEBUG;\n' | ./vendor/bin/phpcs --standard=PluginCheck --sniffs=PluginCheck.CodeAnalysis.PHPErrorReporting -, which should produce no warning. Note an open pull request (#1554) already targets this, so check it before starting.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
PHPErrorReportingSniff warns about debug constants that are only read inside a const statement.
For example, const FOO = WP_DEBUG; gives Detected production-time debug constant definition: WP_DEBUG. even though nothing redefines WP_DEBUG.
Affected code
PHPErrorReportingSniff::check_const_declaration() reports every T_STRING between const and ; that matches WP_DEBUG, WP_DEBUG_LOG, WP_DEBUG_DISPLAY or SCRIPT_DEBUG. It never checks that the token is the name being declared, or that the const is global.
These are flagged by mistake:
const FOO = WP_DEBUG;
const LOG_LEVEL = WP_DEBUG ? 'debug' : 'error';
const MULTI = array( 1, WP_DEBUG ), OTHER = SCRIPT_DEBUG;
class A {
const WP_DEBUG = 1; // Becomes A::WP_DEBUG.
}
namespace MyPlugin;
const WP_DEBUG = true; // Becomes \MyPlugin\WP_DEBUG.
The existing tests only cover const WP_DEBUG = true; and const SOME_OTHER = 1, WP_DEBUG = true;.
Expected behavior
Only report a debug constant when a global const statement declares it. Ignore value reads, class, interface, trait and enum constants, and namespaced const declarations.
Steps to reproduce
-
Run the sniff on a file that only reads a debug constant:
printf '<?php\nconst FOO = WP_DEBUG;\n' | ./vendor/bin/phpcs --standard=PluginCheck --sniffs=PluginCheck.CodeAnalysis.PHPErrorReporting -Or run
wp plugin check <plugin-slug> --checks=php_error_reportingon a plugin that containsconst FOO = WP_DEBUG;. -
Notice the warning:
2 | WARNING | Detected production-time debug constant definition: WP_DEBUG.
Environment
- Plugin Check: trunk (2.2.0)
- WordPress: 6.3+
- PHP: 7.4+
- Ngôn ngữ chính
- PHP
- Star
- 365
- Fork
- 135
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 20
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của WordPress/plugin-check
-
False positive trademarked_term warning for "wc" inside the word "Flowchart"Có thể đã có người làm @anandrajaram21 đã nhận 3 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
WordPress/plugin-check#1556 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add opt-in .distignore exclusions for local and CI scansCó thể đã có người làm @jakaria-istauk đã nhận 1 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
WordPress/plugin-check#1559 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 58/100
WordPress/plugin-check#1557 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
WordPress/plugin-check#1555 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add checks to detect jQuery 4 incompatibilities ahead of WordPress 7.2 / 7.3Có thể đã có người làm @avinash-addweb đã nhận 12 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
WordPress/plugin-check#1549 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của WordPress/plugin-check
Issue tương tự
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
quantum-php/project#222 ·
-
support
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
15.0
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
mailcow/mailcow-dockerized#7717 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
mage-os/devdocs-website#75 ·