Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 27 | class RuleViolationTest extends AbstractTest |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * testConstructorExtractsClassNameFromGivenType |
||
| 31 | * |
||
| 32 | * @return void |
||
| 33 | */ |
||
| 34 | public function testConstructorExtractsClassNameFromGivenType() |
||
| 44 | |||
| 45 | /** |
||
| 46 | * testConstructorExtractsClassNameFromGivenMethod |
||
| 47 | * |
||
| 48 | * @return void |
||
| 49 | */ |
||
| 50 | View Code Duplication | public function testConstructorExtractsClassNameFromGivenMethod() |
|
| 60 | |||
| 61 | /** |
||
| 62 | * testConstructorExtractsMethodNameFromGivenMethod |
||
| 63 | * |
||
| 64 | * @return void |
||
| 65 | */ |
||
| 66 | View Code Duplication | public function testConstructorExtractsMethodNameFromGivenMethod() |
|
| 76 | } |
||
| 77 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: