Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.7.2

Bug #18670 UpperCaseConstantNameSniff fails on dynamic retrieval of class constant
Submitted: 2011-07-16 02:30 UTC
From: treegi Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.3.0)
PHP Version: 5.3.6 OS: Lunux
Roadmaps: (Not assigned)    
Subscription  


 [2011-07-16 02:30 UTC] treegi (Joshua Johnston)
Description: ------------ The constant sniff assumes that arguments to constant() should be all uppercase when it is valid to have constant('self::SOME_CONST'); if you are doing dynamic constant retrieval Test script: --------------- <?php // bug.php class ConstTest { const TESTER = '1'; public function __construct() { echo constant('self::TESTER'); } } ?> Expected result: ---------------- $ phpcs --standard=PEAR bug.php -------------------------------------------------------------------------------- FOUND 6 ERROR(S) AFFECTING 3 LINE(S) -------------------------------------------------------------------------------- 2 | ERROR | Missing file doc comment 2 | ERROR | Missing class doc comment 2 | ERROR | Opening brace of a class must be on the line after the definition 4 | ERROR | Missing function doc comment 4 | ERROR | Opening brace should be on a new line 5 | ERROR | Constants must be uppercase; expected 'SELF::TESTER' but found | | 'self::TESTER' -------------------------------------------------------------------------------- Time: 0 seconds, Memory: 5.25Mb Actual result: -------------- $ phpcs --standard=PEAR bug.php -------------------------------------------------------------------------------- FOUND 5 ERROR(S) AFFECTING 2 LINE(S) -------------------------------------------------------------------------------- 2 | ERROR | Missing file doc comment 2 | ERROR | Missing class doc comment 2 | ERROR | Opening brace of a class must be on the line after the definition 4 | ERROR | Missing function doc comment 4 | ERROR | Opening brace should be on a new line --------------------------------------------------------------------------------

Comments

 [2011-07-18 19:07 UTC] gennadiylitvinyuk (Gennadiy Litvinyuk)
I have the same issue.
 [2011-07-18 19:09 UTC] gennadiylitvinyuk (Gennadiy Litvinyuk)
 [2011-07-18 19:11 UTC] gennadiylitvinyuk (Gennadiy Litvinyuk)
The Patch fixes the problem. It should be applied to PHP/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php
 [2011-07-18 19:23 UTC] treegi (Joshua Johnston)
@Gennadiy The patch works but it doesn't enforce the sniff correctly. constant('self::lowercase') would pass and it shouldn't. For UpperCaseConstantNameSniff a string constant should match the pattern: /^(\w+::)?[A-Z0-9_]+\z/
 [2011-08-05 09:18 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Closed -Assigned To: +Assigned To: squiz
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.