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
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -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);
+22 −0
Original line number Diff line number Diff line
@@ -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;

}
+5 −1
Original line number Diff line number Diff line
@@ -18,7 +18,11 @@ class ValidVariableNameUnitTest extends CoderSniffUnitTest
     */
    public function getErrorList()
    {
        return [3 => 1];
        return [
            3  => 1,
            46 => 1,
            57 => 1,
        ];

    }//end getErrorList()