CRITICAL
Rule Definition
A large number of public methods and attributes declared in a class can indicate that the class may need to be broken up as increased effort will be required to thoroughly test it.
Remediation
Modify the source code of the class to reduce the number of public methods and attributes.
Violation Code Sample
class CastTest
{
public $public1;
public $public2;
//several others public datamembers
public $public20;
public $public21;
public function test1()
{
}
public function test2()
{
}
// Several other complex methods
public function test20()
{
}
public function test21()
{
}
}
Fixed Code Sample
<?php
function getSomething() {
echo "removed unused variable", PHP_EOL; //violation removed
}
class CastTest {
public function doSomething() {
$unusedVariable3 = 20;
echo $unusedVariable3; // violation removed
}
}
getSomething();
$obj = new CastTest();
$obj->doSomething();
?>
Reference
PHPMD - http://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Related Technologies
Technical Criterion
Programming Practices - OO Inheritance and Polymorphism
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.