/** * This method checks the length of the given class node against a configured * threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $threshold = $this->getIntProperty('minimum'); $ignoreWhitespace = $this->getBooleanProperty('ignore-whitespace'); if ($ignoreWhitespace) { $loc = $node->getMetric('eloc'); } else { $loc = $node->getMetric('loc'); } if ($loc < $threshold) { return; } $this->addViolation($node, array($node->getName(), $loc, $threshold)); }
/** * This method should implement the violation analysis algorithm of concrete * rule implementations. All extending classes must implement this method. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $cbo = $node->getMetric('cbo'); if ($cbo >= ($threshold = $this->getIntProperty('minimum'))) { $this->addViolation($node, array($node->getName(), $cbo, $threshold)); } }
/** * This method checks the weighted method count for the given class against * a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $threshold = $this->getIntProperty('maximum'); $actual = $node->getMetric('wmc'); if ($actual >= $threshold) { $this->addViolation($node, array($node->getName(), $actual, $threshold)); } }
/** * This method checks the number of classes derived from the given class * node. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $nocc = $node->getMetric('nocc'); $threshold = $this->getIntProperty('minimum'); if ($nocc >= $threshold) { $this->addViolation($node, array($node->getType(), $node->getName(), $nocc, $threshold)); } }
/** * This method checks the number of public fields and methods in the given * class and checks that value against a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(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 cyclomatic complexity for the given node against * a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $threshold = $this->getIntProperty('reportLevel'); $ccn = $node->getMetric('ccn2'); if ($ccn < $threshold) { return; } $this->addViolation($node, array($node->getType(), $node->getName(), $ccn, $threshold)); }
/** * This method checks the number of methods with in a given class and checks * this number against a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(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 methods with in a given class and checks * this number against a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $this->ignoreRegexp = $this->getStringProperty('ignorepattern'); $threshold = $this->getIntProperty('maxmethods'); if ($node->getMetric('npm') <= $threshold) { return; } $nom = $this->countMethods($node); if ($nom <= $threshold) { return; } $this->addViolation($node, array($node->getType(), $node->getName(), $nom, $threshold)); }
/** * This method checks the number of parents for the given class * node. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { try { $threshold = $this->getIntProperty('maximum'); $comparision = 1; } catch (\OutOfBoundsException $e) { $threshold = $this->getIntProperty('minimum'); $comparision = 2; } $dit = $node->getMetric('dit'); if ($comparision === 1 && $dit > $threshold || $comparision === 2 && $dit >= $threshold) { $this->addViolation($node, array($node->getType(), $node->getName(), $dit, $threshold)); } }
/** * This method checks the number of methods with in a given class and checks * this number against a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { try { $this->ignoreRegexp = $this->getStringProperty('ignorepattern'); } catch (\OutOfBoundsException $e) { $this->ignoreRegexp = self::DEFAULT_IGNORE_REGEXP; } $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)); }
/** * This method checks the cyclomatic complexity for the given node against * a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { if ($node->getMetric('ccn2') <= $this->getIntProperty('maximum')) { return; } $this->addViolation($node, array($node->getParentName(), $node->getName(), $node->getMetric('ccn2'), $this->getIntProperty('maximum')), $node->getMetric('ccn2')); /* @deprecated average calculation if ($node instanceof ClassNode) { $this->classes[$node->getName()] = array_flip($node->getMethodNames()); $this->ccn = 0; $this->count = 0; return; } else if (!($node->getParentType() instanceof InterfaceNode)) { if (false === $node->isAbstract()) { $this->ccn += $node->getMetric('ccn2'); ++$this->count; } unset($this->classes[$node->getParentName()][$node->getName()]); } if (0 === $this->count || false === isset($this->classes[$node->getParentName()]) || 0 < count($this->classes[$node->getParentName()])) { return; } $ccn = $this->ccn / $this->count; if ($ccn < $this->getIntProperty('reportLevel')) { return; } $this->addViolation( $node->getParentType(), array( $node->getParentName(), $ccn, $this->getIntProperty('reportLevel') ), $ccn ); */ }
/** * Tests the code coverage of the given node instance against the configured * minimum threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { if ($node->getMetric('cov') >= $this->getIntProperty('minimum')) { return; } $this->addViolation($node, array($node->getParentName(), $node->getName(), round($node->getMetric('cov'), 2), $this->getIntProperty('minimum')), $node->getMetric('cov')); /* @deprecated average calculation if ($node instanceof ClassNode) { $this->classes[$node->getName()] = array_flip($node->getMethodNames()); $this->coverage = 0; $this->count = 0; return; } else { if (false === $node->isAbstract() && is_numeric($node->getMetric('cov'))) { $this->coverage += $node->getMetric('cov'); ++$this->count; } unset($this->classes[$node->getParentName()][$node->getName()]); } if (0 === $this->count || false === isset($this->classes[$node->getParentName()]) || 0 < count($this->classes[$node->getParentName()])) { return; } $coverage = $this->coverage / $this->count; if ($coverage < $this->getIntProperty('minimum')) { $this->addViolation( $node->getParentType(), array( $node->getParentName(), round($coverage, 2), $this->getIntProperty('minimum') ), $coverage ); } */ }