CRITICAL
Rule Definition
The number of weighted methods of a class is a good indicator of how much time and effort is required to modify and maintain this class. A class with a large number of methods also means that this class has a greater potential impact on derived classes and therefore the cost to maintain and test it is also high.
Remediation
Modify the source code of the class to reduce the number of weighted methods.
Violation Code Sample
class CastTest
{
public function test1()
{
if ($a == $b)
{
if ($a1 == $b1)
{
test();
}
else if ($a2 == $b2)
{
test();
}
else {
}
}
}
public function test2()
{
if ($a == $b)
{
if ($a1 == $b1)
{
test();
}
else if ($a2 == $b2)
{
test();
}
else { }
}
}
// Several other complex methods
}
Fixed Code Sample
"class CAST{
public function close() {
echo 'test';
}
}"
Reference
Code Sniffer http://pear.php.net/package/PHP_CodeSniffer/docs/1.5.2/PHP_CodeSniffer/Generic_Sniffs_CodeAnalysis_UnconditionalIfStatementSniff.html
Related Technologies
Technical Criterion
Programming Practices - Structuredness
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.