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 |
||
7 | final class RawResponse |
||
8 | { |
||
9 | private $raw; |
||
10 | private $values; |
||
11 | private $arrays; |
||
12 | private $maps; |
||
13 | private $tuples; |
||
14 | |||
15 | 43 | public function __construct($raw, array $values, array $arrays, array $maps, array $tuples) |
|
23 | |||
24 | 1 | public function getRaw() |
|
28 | |||
29 | 1 | public function getValues() |
|
33 | |||
34 | 1 | public function getArrays() |
|
38 | |||
39 | 1 | public function getMaps() |
|
43 | |||
44 | 1 | public function getTuples() |
|
48 | |||
49 | 23 | public function hasValue($name) |
|
53 | |||
54 | 23 | View Code Duplication | public function getValue($name) |
64 | |||
65 | 5 | public function hasArray($name) |
|
69 | |||
70 | 5 | View Code Duplication | public function getArray($name) |
80 | |||
81 | 17 | public function hasMap($name) |
|
85 | |||
86 | 17 | View Code Duplication | public function getMap($name) |
96 | |||
97 | 1 | public function getMapValue($name, $key) |
|
101 | |||
102 | 1 | public function getMapKey($name, $value) |
|
108 | |||
109 | 5 | public function hasTuple($name) |
|
113 | |||
114 | 5 | View Code Duplication | public function getTuple($name) |
124 | } |
||
125 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.