/**
  * This method should implement the violation analysis algorithm of concrete
  * rule implementations. All extending classes must implement this method.
  *
  * @param PHP_PMD_AbstractNode $node The current context for analysis.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     $cbo = $node->getMetric('cbo');
     if ($cbo >= ($threshold = $this->getIntProperty('minimum'))) {
         $this->addViolation($node, array($node->getName(), $cbo, $threshold));
     }
 }
Ejemplo n.º 2
0
 /**
  * This method checks the number of methods with in a given class and checks
  * this number against a configured threshold.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     if ($node->getMetric('vars') <= $this->getIntProperty('maxfields')) {
         return;
     }
     $this->addViolation($node);
 }
 /**
  * {@inheritdoc}
  */
 protected function checkNodeImage(PHP_PMD_AbstractNode $node)
 {
     $excludedVariables = explode('|', $this->getStringProperty('excludeVariables'));
     if (!in_array($node->getImage(), $excludedVariables)) {
         parent::checkNodeImage($node);
     }
 }
Ejemplo n.º 4
0
 /**
  * Extracts all variable and variable declarator nodes from the given node
  * and checks the variable name length against the configured minimum
  * length.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     if ($this->getIntProperty('minimum') <= strlen($node->getName())) {
         return;
     }
     $this->addViolation($node, array($node->getParentName(), $node->getName()));
 }
Ejemplo n.º 5
0
 /**
  * This method checks the number of classes derived from the given class
  * node.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     $nocc = $node->getMetric('nocc');
     if ($nocc >= $this->getIntProperty('minimum')) {
         $this->addViolation($node, array($node->getName(), $nocc));
     }
 }
Ejemplo n.º 6
0
 /**
  * This method checks the number of public fields and methods in the given
  * class and checks that value against a configured threshold.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     if ($node->getMetric('cis') < $this->getIntProperty('minimum')) {
         return;
     }
     $this->addViolation($node);
 }
 /**
  * Extracts all variable and variable declarator nodes from the given node
  * and checks the variable name length against the configured minimum
  * length.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     if (strcasecmp($node->getName(), $node->getParentName()) !== 0) {
         return;
     }
     $this->addViolation($node);
 }
Ejemplo n.º 8
0
 /**
  * This method checks the number of arguments for the given function or method
  * node against a configured threshold.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     if ($node->getParameterCount() < $this->getIntProperty('minimum')) {
         return;
     }
     $this->addViolation($node);
 }
 /**
  * This method checks if a superglobal is used
  * and emits a rule violation.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     foreach ($node->findChildrenOfType('Variable') as $variable) {
         if (in_array($variable->getImage(), $this->superglobals)) {
             $this->addViolation($node, array($node->getName(), $variable->getImage()));
         }
     }
 }
 /**
  * This method checks if a variable is not named in camelCase
  * and emits a rule violation.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     foreach ($node->findChildrenOfType('Variable') as $variable) {
         if (!preg_match('/^\\$[a-z][a-zA-Z0-9]*$/', $variable->getImage())) {
             $this->addViolation($node, array($variable->getImage()));
         }
     }
 }
 /**
  * This method checks the number of parents for the given class
  * node.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     $threshold = $this->getIntProperty('minimum');
     $dit = $node->getMetric('dit');
     if ($dit >= $threshold) {
         $this->addViolation($node, array($node->getType(), $node->getName(), $dit, $threshold));
     }
 }
Ejemplo n.º 12
0
 /**
  * This method checks the length of the given class node against a configured
  * threshold.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     $loc = $node->getMetric('loc');
     if ($loc < $this->getIntProperty('minimum')) {
         return;
     }
     $this->addViolation($node, array($node->getName(), $loc));
 }
Ejemplo n.º 13
0
 /**
  * This method checks the acyclic complexity for the given node against a
  * configured threshold.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     $npath = $node->getMetric('npath');
     if ($npath < $this->getIntProperty('minimum')) {
         return;
     }
     $this->addViolation($node, array($node->getType(), $node->getName(), $npath));
 }
Ejemplo n.º 14
0
 /**
  * This method checks the weighted method count for the given class against
  * a configured threshold.
  *
  * @param PHP_PMD_AbstractNode $node The context class node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     $threshold = $this->getIntProperty('maximum');
     $actual = $node->getMetric('wmc');
     if ($actual >= $threshold) {
         $this->addViolation($node, array($node->getName(), $actual, $threshold));
     }
 }
 /**
  * This method checks if a method is not named in camelCase
  * and emits a rule violation.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     if (!in_array($node->getName(), $this->ignoredMethods)) {
         if (!preg_match('/^[a-z][a-zA-Z0-9]*$/', $node->getName())) {
             $this->addViolation($node, array($node->getName()));
         }
     }
 }
 /**
  * This method checks if a parameter is not named in camelCase
  * and emits a rule violation.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     foreach ($node->getParameters() as $parameter) {
         if (!preg_match('/^\\$[a-z][a-zA-Z0-9]*$/', $parameter->getName())) {
             $this->addViolation($node, array($parameter->getName()));
         }
     }
 }
Ejemplo n.º 17
0
 /**
  * This method checks the cyclomatic complexity for the given node against
  * a configured threshold.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     $ccn = $node->getMetric('ccn2');
     if ($ccn < $this->getIntProperty('reportLevel')) {
         return;
     }
     $this->addViolation($node, array($node->getType(), $node->getName(), $ccn));
 }
 /**
  * Extracts all constant declarations from the given node and tests that
  * the image only contains upper case characters.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     foreach ($node->findChildrenOfType('ConstantDeclarator') as $declarator) {
         if ($declarator->getImage() !== strtoupper($declarator->getImage())) {
             $this->addViolation($declarator, array($declarator->getImage()));
         }
     }
 }
Ejemplo n.º 19
0
 /**
  * Constructs a new collection instance.
  *
  * @param PHP_PMD_AbstractNode $node The context/parent node.
  */
 public function __construct(PHP_PMD_AbstractNode $node)
 {
     preg_match_all($this->_regexp, $node->getDocComment(), $matches);
     foreach (array_keys($matches[0]) as $i) {
         $name = $matches[1][$i];
         $value = trim($matches[2][$i], '" ');
         $this->_annotations[] = new PHP_PMD_Node_Annotation($name, $value);
     }
 }
 /**
  * This method checks the number of methods with in a given class and checks
  * this number against a configured threshold.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     $threshold = $this->getIntProperty('maxfields');
     $vars = $node->getMetric('vars');
     if ($vars <= $threshold) {
         return;
     }
     $this->addViolation($node, array($node->getType(), $node->getName(), $vars, $threshold));
 }
 /**
  * This method checks the number of public fields and methods in the given
  * class and checks that value against a configured threshold.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     $threshold = $this->getIntProperty('minimum');
     $cis = $node->getMetric('cis');
     if ($cis < $threshold) {
         return;
     }
     $this->addViolation($node, array($node->getType(), $node->getName(), $cis, $threshold));
 }
 /**
  * This method checks the number of arguments for the given function or method
  * node against a configured threshold.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     $threshold = $this->getIntProperty('minimum');
     $count = $node->getParameterCount();
     if ($count < $threshold) {
         return;
     }
     $this->addViolation($node, array($node->getType(), $node->getName(), $count, $threshold));
 }
Ejemplo n.º 23
0
 /**
  * This method checks the lines of code length for the given function or
  * methode node against a configured threshold.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     $loc = $node->getMetric('loc');
     if ($loc < $this->getIntProperty('minimum')) {
         return;
     }
     $type = explode('_', get_class($node));
     $type = strtolower(array_pop($type));
     $this->addViolation($node, array($type, $node->getName(), $loc));
 }
 public function apply(PHP_PMD_AbstractNode $node)
 {
     $staticReferences = $node->findChildrenOfType('ClassOrInterfaceReference');
     foreach ($staticReferences as $reference) {
         if ($this->isReferenceInParameter($reference)) {
             continue;
         }
         $this->addViolation($reference, array($reference->getImage(), $node->getImage()));
     }
 }
Ejemplo n.º 25
0
 /**
  * Method checks for use of static access and warns about it.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     $nodes = $node->findChildrenOfType('MemberPrimaryPrefix');
     foreach ($nodes as $methodCall) {
         if (!$this->isStaticMethodCall($methodCall)) {
             continue;
         }
         $this->addViolation($methodCall, array($methodCall->getImage(), $methodCall->getImage()));
     }
 }
Ejemplo n.º 26
0
 /**
  * This method checks the number of methods with in a given class and checks
  * this number against a configured threshold.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     if ($node->getMetric('nom') <= $this->getIntProperty('maxmethods')) {
         return;
     }
     if ($this->_countMethods($node) <= $this->getIntProperty('maxmethods')) {
         return;
     }
     $this->addViolation($node);
 }
 public function apply(PHP_PMD_AbstractNode $node)
 {
     foreach ($node->findChildrenOfType('FormalParameter') as $param) {
         $declarator = $param->getFirstChildOfType('VariableDeclarator');
         $value = $declarator->getValue();
         if (!$this->isBooleanValue($value)) {
             continue;
         }
         $this->addViolation($param, array($node->getImage(), $declarator->getImage()));
     }
 }
 public function apply(PHP_PMD_AbstractNode $node)
 {
     return;
     // not good enough, if, elseif,... nest each other and get detected by this rule :(
     foreach ($node->findChildrenOfType('ScopeStatement') as $scope) {
         if (!$this->isNestedScope($scope)) {
             continue;
         }
         $this->addViolation($scope, array($node->getImage()));
     }
 }
Ejemplo n.º 29
0
 /**
  * This method checks the number of methods with in a given class and checks
  * this number against a configured threshold.
  *
  * @param PHP_PMD_AbstractNode $node The context source code node.
  *
  * @return void
  */
 public function apply(PHP_PMD_AbstractNode $node)
 {
     $threshold = $this->getIntProperty('maxmethods');
     if ($node->getMetric('nom') <= $threshold) {
         return;
     }
     $nom = $this->_countMethods($node);
     if ($nom <= $threshold) {
         return;
     }
     $this->addViolation($node, array($node->getType(), $node->getName(), $nom, $threshold));
 }
 public function apply(PHP_PMD_AbstractNode $node)
 {
     foreach ($node->findChildrenOfType('ScopeStatement') as $scope) {
         $parent = $scope->getParent();
         if (!$this->isIfOrElseIfStatement($parent)) {
             continue;
         }
         if (!$this->isElseScope($scope, $parent)) {
             continue;
         }
         $this->addViolation($scope, array($node->getImage()));
     }
 }