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 |
||
| 9 | class Time extends AbstractField |
||
| 10 | { |
||
| 11 | use Orderable; |
||
| 12 | use Nullable; |
||
| 13 | use Placeholder; |
||
| 14 | |||
| 15 | const TOP = 'top'; |
||
| 16 | const RIGHT = 'right'; |
||
| 17 | const BOTTOM = 'bottom'; |
||
| 18 | const LEFT = 'left'; |
||
| 19 | |||
| 20 | protected $placement = 'bottom'; |
||
| 21 | |||
| 22 | 2 | public function placement(string $placement) |
|
| 38 | |||
| 39 | 3 | public function getPlacement() |
|
| 43 | |||
| 44 | 3 | View Code Duplication | public function default($value) |
| 55 | |||
| 56 | public function getListValue($model) |
||
| 63 | |||
| 64 | public function getEditFormValue($model) |
||
| 73 | |||
| 74 | public function getCreateFormValue() |
||
| 80 | } |
||
| 81 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.