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 |
||
18 | class NaptrRecord extends Record |
||
19 | { |
||
20 | /** |
||
21 | * @var Int |
||
22 | */ |
||
23 | protected $order; |
||
24 | /** |
||
25 | * @var Int |
||
26 | */ |
||
27 | protected $preference; |
||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | protected $flags; |
||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $services; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $regexp; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $replacement; |
||
46 | |||
47 | /** |
||
48 | * NaptrRecord constructor. |
||
49 | * |
||
50 | * @param Node $node |
||
51 | * @param int $ttl |
||
52 | * @param int $order |
||
53 | * @param int $preference |
||
54 | * @param string $flags |
||
55 | * @param string $services |
||
56 | * @param string $regexp |
||
57 | * @param string $replacement |
||
58 | */ |
||
59 | public function __construct(Node $node, int $ttl, |
||
71 | |||
72 | /** |
||
73 | * @return string |
||
74 | */ |
||
75 | public function __toString(): string |
||
87 | |||
88 | /** |
||
89 | * @return Int |
||
90 | */ |
||
91 | public function getOrder() |
||
95 | |||
96 | /** |
||
97 | * @param Int $order |
||
98 | * |
||
99 | * @return Record |
||
100 | */ |
||
101 | public function setOrder(Int $order) |
||
105 | |||
106 | /** |
||
107 | * @return Int |
||
108 | */ |
||
109 | public function getPreference() |
||
113 | |||
114 | /** |
||
115 | * @param Int $preference |
||
116 | * |
||
117 | * @return Record |
||
118 | */ |
||
119 | public function setPreference(Int $preference) |
||
123 | |||
124 | /** |
||
125 | * @return string |
||
126 | */ |
||
127 | public function getFlags() |
||
131 | |||
132 | /** |
||
133 | * @param string $flags |
||
134 | * |
||
135 | * @return Record |
||
136 | */ |
||
137 | public function setFlags(string $flags) |
||
141 | |||
142 | /** |
||
143 | * @return string |
||
144 | */ |
||
145 | public function getServices() |
||
149 | |||
150 | /** |
||
151 | * @param string $services |
||
152 | * |
||
153 | * @return Record |
||
154 | */ |
||
155 | public function setServices(string $services) |
||
159 | |||
160 | /** |
||
161 | * @return string |
||
162 | */ |
||
163 | public function getRegexp() |
||
167 | |||
168 | /** |
||
169 | * @param string $regexp |
||
170 | * |
||
171 | * @return Record |
||
172 | */ |
||
173 | public function setRegexp(string $regexp) |
||
177 | |||
178 | /** |
||
179 | * @return string |
||
180 | */ |
||
181 | public function getReplacement() |
||
185 | |||
186 | /** |
||
187 | * @param string $replacement |
||
188 | * |
||
189 | * @return Record |
||
190 | */ |
||
191 | public function setReplacement(string $replacement) |
||
195 | |||
196 | /** |
||
197 | * @return bool |
||
198 | */ |
||
199 | View Code Duplication | public function validate(): bool |
|
221 | |||
222 | /** |
||
223 | * @return array |
||
224 | */ |
||
225 | protected function recordDataToArray(): array |
||
236 | } |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.