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 |
||
19 | class ReflectionReader implements ReaderInterface |
||
20 | { |
||
21 | /** @var \ReflectionClass */ |
||
22 | protected $reflectionClass; |
||
23 | |||
24 | /** @var Tokenizer */ |
||
25 | protected $tokenizer; |
||
26 | |||
27 | /** |
||
28 | * @param string $class |
||
29 | * @return Reflection |
||
30 | * @throws ReaderException |
||
31 | */ |
||
32 | 8 | public function read(string $class) : Reflection |
|
47 | |||
48 | /** |
||
49 | * @return Collection |
||
50 | */ |
||
51 | 7 | protected function readAnnotationsFromClass() : Collection |
|
57 | |||
58 | /** |
||
59 | * @return array|Collection[] |
||
60 | */ |
||
61 | 7 | View Code Duplication | protected function readAnnotationsFromMethods() : array |
75 | |||
76 | /** |
||
77 | * @return array|Collection[] |
||
78 | */ |
||
79 | 7 | View Code Duplication | protected function readAnnotationsFromProperties() : array |
93 | |||
94 | /** |
||
95 | * @param string|bool $comment |
||
96 | * @return array|Annotation[] |
||
97 | */ |
||
98 | 7 | protected function parseComment($comment = false) : array |
|
113 | |||
114 | /** |
||
115 | * @param string $line |
||
116 | * @return bool|Annotation |
||
117 | */ |
||
118 | 7 | protected function parseLine(string $line) |
|
127 | |||
128 | /** |
||
129 | * @param string $line |
||
130 | * @return array |
||
131 | */ |
||
132 | 7 | protected function parseArgumentsFromLine(string $line) : array |
|
153 | |||
154 | /** |
||
155 | * @param string $line |
||
156 | * @return array |
||
157 | */ |
||
158 | 7 | protected function exportArgumentsFromLine(string $line) : array |
|
166 | |||
167 | /** |
||
168 | * @param string $name |
||
169 | * @return string |
||
170 | */ |
||
171 | protected function filterName(string $name) : string |
||
177 | |||
178 | /** |
||
179 | * @param string $value |
||
180 | * @return int|string|bool|float|array |
||
181 | */ |
||
182 | 7 | protected function filterValue(string $value) |
|
189 | |||
190 | /** |
||
191 | * @param string $name |
||
192 | * @param array $arguments |
||
193 | */ |
||
194 | 7 | protected function filterArguments(string $name, array &$arguments) |
|
211 | } |
||
212 |
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.