1.2.25. Already Parents Interface¶
The same interface is implemented by a class and one of its children.
That way, the child doesn’t need to implement the interface, nor define its methods to be an instance of the interface. This analysis may report classes which do not explicitly implements any interfaces : the issue is then coming from the parents.
<?php
interface i {
function i();
}
class A implements i {
function i() {
return __METHOD__;
}
}
// This implements is useless.
class AB extends A implements i {
// No definition for function i()
}
// Implements i is understated
class AB extends A {
// redefinition of the i method
function i() {
return __METHOD__.' ';
}
}
$x = new AB;
var_dump($x instanceof i);
// true
$x = new AC;
var_dump($x instanceof i);
// true
?>
1.2.25.1. Connex PHP features¶
1.2.25.1.1. Suggestions¶
Keep the implements call in the class that do implements the methods. Remove it from the children classes.
1.2.25.1.2. Specs¶
Short name |
Interfaces/AlreadyParentsInterface |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Instant (5 mins) |
Precision |
Very high |
Examples |
|
Available in |