PHPErrorReportingSniff flags debug constants used as values in const declarations
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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+
- 主要言語
- PHP
- スター
- 365
- フォーク
- 135
- 平均マージ
- 1日 8時間
- マージ済み PR(30日)
- 20
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
WordPress/plugin-check のほかの issue
-
False positive trademarked_term warning for "wc" inside the word "Flowchart"対応中かも @anandrajaram21 が 3 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
WordPress/plugin-check#1556 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Add opt-in .distignore exclusions for local and CI scans対応中かも @jakaria-istauk が 1 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
WordPress/plugin-check#1559 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 58/100
WordPress/plugin-check#1557 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
WordPress/plugin-check#1555 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Add checks to detect jQuery 4 incompatibilities ahead of WordPress 7.2 / 7.3対応中かも @avinash-addweb が 12 日前に担当しました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
WordPress/plugin-check#1549 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
WordPress/plugin-check の issue をすべて見る
似ている issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
quantum-php/project#222 ·
-
support
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
15.0
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
mailcow/mailcow-dockerized#7717 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
mage-os/devdocs-website#75 ·