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 Datetime extends AbstractField |
||
| 10 | { |
||
| 11 | use Orderable; |
||
| 12 | use Nullable; |
||
| 13 | use Placeholder; |
||
| 14 | |||
| 15 | protected $format = 'YYYY-MM-DD HH:mm:ss'; |
||
| 16 | |||
| 17 | 1 | public function format(string $momentJsFormat) |
|
| 23 | |||
| 24 | 2 | public function getDateFormat() |
|
| 28 | |||
| 29 | 3 | View Code Duplication | public function default($value) |
| 40 | |||
| 41 | public function getListValue($model) |
||
| 48 | |||
| 49 | public function getEditFormValue($model) |
||
| 58 | |||
| 59 | public function getCreateFormValue() |
||
| 65 | } |
||
| 66 |
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.