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 |
||
| 8 | class Info extends Fields\Field implements FormatInterface |
||
| 9 | { |
||
| 10 | use Traits\HtmlValueTrait; |
||
| 11 | |||
| 12 | public function __construct() |
||
| 19 | |||
| 20 | /** |
||
| 21 | * {@inheritdoc} |
||
| 22 | */ |
||
| 23 | View Code Duplication | protected function defaultRender($prepend = '', $append = '') |
|
| 41 | } |
||
| 42 |
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: