PHPErrorReportingSniff flags debug constants used as values in const declarations
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- Medio día
- Aptitud para principiantes
- 35/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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+
- Lenguaje dominante
- PHP
- Estrellas
- 365
- Forks
- 135
- Merge medio
- 1 d 8 h
- PR fusionados (30 d)
- 20
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de WordPress/plugin-check
-
False positive trademarked_term warning for "wc" inside the word "Flowchart"Posiblemente ocupada @anandrajaram21 la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
WordPress/plugin-check#1556 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Add opt-in .distignore exclusions for local and CI scansPosiblemente ocupada @jakaria-istauk la tomó hace 1 día. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
WordPress/plugin-check#1559 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 58/100
WordPress/plugin-check#1557 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
WordPress/plugin-check#1555 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Add checks to detect jQuery 4 incompatibilities ahead of WordPress 7.2 / 7.3Posiblemente ocupada @avinash-addweb la tomó hace 12 días. Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 38/100
WordPress/plugin-check#1549 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de WordPress/plugin-check
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
ExpressionEngine/ExpressionEngine#5493 ·
Los mantenedores suelen responder en 5 días
-
"Attempt to read property 'username' on null" error after a user is deletedPosiblemente ocupada @dicksonlaw583 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
omeka/plugin-SimplePages#49 ·
-
Bug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
quantum-php/project#222 ·
-
support
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día