-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Describe the bug
While working with a Laravel project, I try to add sniffs to restrict the code to camel case variables but allow member variables not following this rule since model instances can have properties for the columns in the table which can follow snake case.
Using the Squiz standard to setup naming convention, I try to use NotCamelCaps with MemberNotCamelCaps disabled, but the former seems to interfere whenever I use a member property in any method, flagging it as invalid.
This can be reproduced with the following example:
Code sample
class Test {
public $test_var = null; // Notice how this is not declared as an error.
public function main() {
$this->test_var = 1; // However, whenever I use the variable, I get an error of invalid format.
}
}Custom ruleset
<?xml version="1.0"?>
<ruleset name="My Custom Standard">
<rule ref="Squiz.NamingConventions.ValidVariableName" />
<rule ref="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps">
<severity>0</severity>
</rule>
</ruleset>To reproduce
Steps to reproduce the behavior:
- Create a file called
test.phpwith the code sample above. - Run
phpcs test.php -susing the standard ruleset provided above. - See error message displayed
FILE: ./test.php
----------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------------------
7 | ERROR | Variable "test_var" is not in valid camel caps format
| | (Squiz.NamingConventions.ValidVariableName.NotCamelCaps)
----------------------------------------------------------------------------------------------------------------------------
Time: 16ms; Memory: 4MB
Expected behavior
NotCamelCaps should not show an error for member variables when MemberNotCamelCaps is disabled.
Versions (please complete the following information):
- OS: Using Ubuntu, but this might happen in any.
- PHP: 7.4
- PHPCS: 3.5.8
- Standard: Squiz