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 Element extends AbstractElement |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var null|DefaultAction |
||
| 13 | */ |
||
| 14 | private $defaultAction; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var null|Button[] |
||
| 18 | */ |
||
| 19 | private $buttons; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param string $title |
||
| 23 | */ |
||
| 24 | 9 | public function __construct($title, $subtitle = null, $imageUrl = null, array $buttons = null, DefaultAction $defaultAction = null) |
|
| 35 | |||
| 36 | /** |
||
| 37 | * @return null|Button[] |
||
| 38 | */ |
||
| 39 | 1 | public function getButtons() |
|
| 43 | |||
| 44 | /** |
||
| 45 | * @return null|DefaultAction |
||
| 46 | */ |
||
| 47 | 1 | public function getDefaultAction() |
|
| 51 | |||
| 52 | /** |
||
| 53 | * @return array |
||
| 54 | */ |
||
| 55 | 1 | View Code Duplication | public function jsonSerialize() |
| 65 | } |
||
| 66 |