public function apply(PHPUnit_Util_Metrics $metrics) { $locExecutable = $metrics->getLocExecutable(); if ($locExecutable > $this->threshold) { return sprintf("Class has %d lines of executable code.\n" . 'This is an indication that the class may be ' . 'trying to do too much. Try to break it down, ' . 'and reduce the size to something manageable.', $locExecutable); } }
public function apply(PHPUnit_Util_Metrics $metrics) { $parameters = $metrics->getParameters(); if ($parameters >= $this->threshold) { return sprintf("Function or method has %d parameters.\n" . 'Long parameter lists can indicate that a new object should be ' . 'created to wrap the numerous parameters. Basically, try to ' . 'group the parameters together.', $parameters); } }
public function apply(PHPUnit_Util_Metrics $metrics) { $npath = $metrics->getNPath(); if ($npath >= $this->threshold) { return sprintf("The NPath complexity is %d.\n" . 'The NPath complexity of a function or method is the number of ' . 'acyclic execution paths through that method. A threshold of 200 ' . 'is generally considered the point where measures should be taken ' . 'to reduce complexity.', $npath); } }
public function apply(PHPUnit_Util_Metrics $metrics) { $locExecutable = $metrics->getLocExecutable(); if ($locExecutable >= $this->threshold) { return sprintf("Function or method has %d lines of executable code.\n" . 'Violations of this rule usually indicate that the method is ' . 'doing too much. Try to reduce the method size by creating ' . 'helper methods and removing any copy/pasted code.', $locExecutable); } }
public function apply(PHPUnit_Util_Metrics $metrics) { $ccn = $metrics->getCCN(); if ($ccn >= $this->threshold) { return sprintf("The cyclomatic complexity is %d.\n" . 'Complexity is determined by the number of decision points in a ' . 'function or method plus one for the function or method entry. ' . 'The decision points are "if", "for", "foreach", "while", "case", ' . '"catch", "&&", "||", and "?:". Generally, 1-4 is low ' . 'complexity, 5-7 indicates moderate complexity, 8-10 is high ' . 'complexity, and 11+ is very high complexity.', $ccn); } }
public function apply(PHPUnit_Util_Metrics $metrics) { $crap = $metrics->getCrapIndex(); if ($crap >= $this->threshold) { return sprintf("The CRAP index is %d.\n" . 'The Change Risk Analysis and Predictions (CRAP) index of a ' . 'function or method uses cyclomatic complexity and code coverage ' . 'from automated tests to help estimate the effort and risk ' . 'associated with maintaining legacy code. A CRAP index over 30 ' . 'is a good indicator of crappy code.', $crap); } }
public function apply(PHPUnit_Util_Metrics $metrics) { $ce = $metrics->getCe(); if ($ce > $this->threshold) { return sprintf("Class depends on %d other classes.\n" . 'The number of other classes that the class ' . 'depends upon is an indicator of the class\' ' . 'independence.', $ce); } }
public function apply(PHPUnit_Util_Metrics $metrics) { $dit = $metrics->getDIT(); if ($dit > $this->threshold) { return sprintf('Depth of Inheritance Tree (DIT) is %d.', $dit); } }
public function apply(PHPUnit_Util_Metrics $metrics) { $publicMethods = $metrics->getPublicMethods(); if ($publicMethods > $this->threshold) { return sprintf("Class has %d public methods.\n" . 'A large number of public methods and attributes ' . 'declared in a class can indicate the class may need ' . 'to be broken up as increased effort will be required ' . 'to thoroughly test it.', $publicMethods); } }
public function apply(PHPUnit_Util_Metrics $metrics) { $varsNp = $metrics->getVARSnp(); if ($varsNp > $this->threshold) { return sprintf("Class has %d public fields.\n" . 'Classes that have too many fields could be redesigned ' . 'to have fewer fields, possibly through some nested ' . 'object grouping of some of the information. For ' . 'example, a class with city/state/zip fields could ' . 'instead have one Address field.', $varsNp); } }
public function apply(PHPUnit_Util_Metrics $metrics) { $coverage = $metrics->getCoverage(); if ($coverage <= $this->threshold[0]) { $violation = 'The code coverage is %01.2F which is considered low.'; } else { if ($coverage > $this->threshold[0] && $coverage < $this->threshold[1]) { $violation = 'The code coverage is %01.2F which is considered medium.'; } } if (isset($violation)) { return sprintf($violation, $coverage); } }
public function apply(PHPUnit_Util_Metrics $metrics) { $numCrappyMethods = 0; $numMethods = 0; foreach ($metrics->getClasses() as $class) { $methods = $class->getMethods(); foreach ($methods as $method) { if ($method->getCrapIndex() > $this->threshold[1]) { $numCrappyMethods++; } } $numMethods += count($methods); } if ($numMethods > 0) { $percent = $numCrappyMethods / $numMethods * 100; } else { $percent = 0; } if ($percent > $this->threshold[0]) { return sprintf("More than %01.2f%% of the project's methods have a Change Risk " . 'Analysis and Predictions (CRAP) index that is above the threshold ' . "of %d.\n" . 'The CRAP index of a function or method uses cyclomatic complexity ' . 'and code coverage from automated tests to help estimate the ' . 'effort and risk associated with maintaining legacy code. A CRAP ' . 'index over 30 is a good indicator of crappy code.', $this->threshold[0], $this->threshold[1]); } }