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

Request #20090 The sniff about constant name case should only be pllied on definition
Submitted: 2013-10-09 16:10 UTC
From: stof Assigned: squiz
Status: Closed Package: PHP_CodeSniffer
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 46 - 34 = ?

 
 [2013-10-09 16:10 UTC] stof (Christophe Coevoet)
Description: ------------ This sniff currently complains about places using constants which are not named in upper case. But this means that it is complaining about code whic may be out of our control (the constants may be defined in some vendor code, for instance doctrine2 is using some camelCased constants for its events). Using a constant requires using the name used when defining it. So the sniff should only check constant definition.

Comments

 [2013-10-31 05:12 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Closed -Type: Bug +Type: Feature/Change Request -Assigned To: +Assigned To: squiz
I agree that there is no need for the sniff to do checks on usage, although that's how it was designed. This is obviously a BC break, so I've put it into the 1.5.x branch only. The commit is here: https://github.com/squizlabs/PHP_CodeSniffer/commit/4af13118b1fedd89faadd78b9bc cf858ce21dbc9
 [2013-11-28 13:38 UTC] konafets (Stefano Kowalke)
As an addition to this. You should ignore 3rd-party code. Otherwise the CodeSniffer will complain about every violation in this code.
 [2013-11-29 05:46 UTC] squiz (Greg Sherwood)
PHPCS has no way of knowing what is 3rd party code unless you tell it, which you can do by setting ignore settings either on the command line or in your ruleset.xml file. Take a look at the ruleset exclude-pattern tag: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml Or the command line arg or comments you can use: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-files- and-folders
 [2013-12-02 20:59 UTC] stof (Christophe Coevoet)
I never suggested that PHPCS should be able to identify third party code, (and I am already excluding it). The bug report was only about violations added for usage of constants with non-uppercase names, while only the definition of constants should trigger the warning (the usage must use the case used when defining the constant, even when it does not fit the coding standards of the project). Complaining on usage meant that PHPCS was adding violations in places where your code was using a constants coming form a third-party package (and so you cannot rename the constant to fix the violation) And according to the first comment, this issue has been fixed in 1.5
 [2013-12-03 05:56 UTC] squiz (Greg Sherwood)
Sorry Christophe, my comment was in reply to Stefano and not your original report. After I closed it, Stefano commented that PHPCS should just ignore 3rd party code, so I was just explaining how that is done.