Closed ARH-Digital closed 7 years ago
There is no way for PHPCS to know if that member var has been set with an invalid name, or if it has been set to match a DB column name, or if it is being access using __get(). Either way, the member var name is now in the correct format and so it throws an error.
The alternative is to never check any accessed member vars. I'm not sure that it is a good change.
In my standard I've modified the ValidVariableNameSniff
to only check class property declaration, not usage. This way if the property name is wrong I get 1 error instead lots of them on every usage place.
Also with following code in checked file I also don't get false positives, because I'm not in control of XML that needs to be parsed and that surely won't be compliant with used PHPCS standard.
$xml = simplexml_load_string('<root><tag_name>test</tag_name></root>');
$tagName = $xml->tag_name;
I just ran into this.. Looking at the code I can see a few possible fixes ...
Closing this as this isn't a change I intend to make to the sniff.
Using Zend rules. Zend/Sniffs/NamingConventions/ValidVariableNameSniff.php
Incorrectly ignores T_OBJECT_OPERATOR, example,
$Index->short_name = $Data;
135 | ERROR | Variable "short_name" is not in valid camel caps format
short_name
should not be considered a variable, or it should be excluded due to the operator. This is a snake_cased value for a database column. It is not proceeded by a $ either.