1.2.1305. Unused Private Methods¶
Private methods that are not used in the local class are dead code. Protected methods that are not used in the local class or its children, are dead code.
Private methods are reserved for the defining class. Thus, they must be used with the current class, with $this
or self\:\:
.
Protected methods, in a standalone class, are also included.
This analysis skips classes that makes self dynamic calls, such as $this->$method()
.
<?php
class Foo {
// Those methods are used
private function method() {}
private static function staticMethod() {}
// Those methods are not used
private function unusedMethod() {}
private static function staticUnusedMethod() {}
public function bar() {
self::staticMethod();
$this->method();
}
}
?>
1.2.1305.1. Connex PHP features¶
1.2.1305.1.1. Suggestions¶
Remove the private method, as it is unused
Add a call to this private method
Change method visibility to make it available to other classes
1.2.1305.1.2. Specs¶
Short name |
Classes/UnusedPrivateMethod |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Related rule |
|
Available in |