Commit c1693696 authored by Jeroen Tubex's avatar Jeroen Tubex Committed by Klaus Purer
Browse files

fix(ValidVariableName): Allow underscore variable names for plugin annotation...

fix(ValidVariableName): Allow underscore variable names for plugin annotation class properties (#2804739)
parent 6e88ebe8
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -62,7 +62,28 @@ class ValidVariableNameSniff extends AbstractVariableSniff
            if ($extendsName !== false && strpos($extendsName, 'ConfigEntity') !== false) {
                return;
            }

            // Plugin annotations may have underscores in class properties.
            // For example, see \Drupal\Core\Field\Annotation\FieldFormatter.
            // The only class named "Plugin" in Drupal core is
            // \Drupal\Component\Annotation\Plugin while many Views plugins
            // extend \Drupal\views\Annotation\ViewsPluginAnnotationBase.
            if ($extendsName !== false && in_array(
                $extendsName,
                [
                 'Plugin',
                 'ViewsPluginAnnotationBase',
                ]
            ) !== false
            ) {
                return;
            }

            $implementsNames = $phpcsFile->findImplementedInterfaceNames($classPtr);
            if ($implementsNames !== false && in_array('AnnotationInterface', $implementsNames) !== false) {
                return;
            }
        }//end if

        $error = 'Class property %s should use lowerCamel naming without underscores';
        $data  = array($tokens[$stackPtr]['content']);
+33 −0
Original line number Diff line number Diff line
@@ -2,3 +2,36 @@

$UppperCamelName = 0;
$lowerCamelName = 1;

class TestAnnotationProperties extends Plugin {

  /**
   * The entity_type.
   *
   * @var string
   */
  public $entity_type;

}

class TestAnnotationProperties2 extends ViewsPluginAnnotationBase {

  /**
   * The entity_type.
   *
   * @var string
   */
  public $entity_type;

}

class TestAnnotationProperties3 implements AnnotationInterface {

  /**
   * The entity_type.
   *
   * @var string
   */
  public $entity_type;

}