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 |
||
13 | View Code Duplication | class UrlIcon extends SerializeToString implements IconInterface |
|
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $iconUrl; |
||
19 | |||
20 | /** |
||
21 | * UrlIcon constructor. |
||
22 | * |
||
23 | * @param string $iconUrl |
||
24 | */ |
||
25 | 5 | public function __construct($iconUrl) |
|
29 | |||
30 | /** |
||
31 | * This will set the icon if the url is valid. |
||
32 | * |
||
33 | * @param string $iconUrl |
||
34 | * |
||
35 | * @throws InvalidUrlException Thrown when the url is not valid |
||
36 | * |
||
37 | * @return $this |
||
38 | */ |
||
39 | 5 | private function setIcon($iconUrl) |
|
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 3 | public function getIcon() |
|
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | 2 | public function __toString() |
|
69 | |||
70 | /** |
||
71 | * @inheritDoc |
||
72 | */ |
||
73 | public function getType() |
||
77 | } |
||
78 |