Skip to content
Snippets Groups Projects
Commit a11339f8 authored by Nikolay Lobachev's avatar Nikolay Lobachev Committed by Klaus Purer
Browse files

fix(ValidVariableName): Check that class properties start with lower case...

fix(ValidVariableName): Check that class properties start with lower case (#2972167 by mail@michaelwelford.com)
parent 7b3db8a7
No related branches found
No related tags found
No related merge requests found
......@@ -43,12 +43,6 @@ class ValidVariableNameSniff extends AbstractVariableSniff
return;
}
$memberName = ltrim($tokens[$stackPtr]['content'], '$');
if (strpos($memberName, '_') === false) {
return;
}
// Check if the class extends another class and get the name of the class
// that is extended.
if (empty($tokens[$stackPtr]['conditions']) === false) {
......@@ -85,6 +79,13 @@ class ValidVariableNameSniff extends AbstractVariableSniff
}
}//end if
// The name of a property must start with a lowercase letter, properties
// with underscores are not allowed, except the cases handled above.
$memberName = ltrim($tokens[$stackPtr]['content'], '$');
if (preg_match('/^[a-z]/', $memberName) === 1 && strpos($memberName, '_') === false) {
return;
}
$error = 'Class property %s should use lowerCamel naming without underscores';
$data = [$tokens[$stackPtr]['content']];
$phpcsFile->addError($error, $stackPtr, 'LowerCamelName', $data);
......
......@@ -35,3 +35,25 @@ class TestAnnotationProperties3 implements AnnotationInterface {
public $entity_type;
}
class TestAnnotationProperties4 {
/**
* The MyVariable.
*
* @var string
*/
public $MyVariable;
}
class TestAnnotationProperties5 {
/**
* The my_variable.
*
* @var string
*/
public $my_variable;
}
......@@ -18,7 +18,11 @@ class ValidVariableNameUnitTest extends CoderSniffUnitTest
*/
public function getErrorList()
{
return [3 => 1];
return [
3 => 1,
46 => 1,
57 => 1,
];
}//end getErrorList()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment