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 |
||
11 | class DocumentorService extends Service |
||
12 | { |
||
13 | /** |
||
14 | * @Inyectable |
||
15 | * @var \PSFS\base\Router route |
||
16 | */ |
||
17 | protected $route; |
||
18 | |||
19 | /** |
||
20 | * Method that extract all modules |
||
21 | * @return array |
||
22 | */ |
||
23 | public function getModules() |
||
41 | |||
42 | /** |
||
43 | * Method that extract all endpoints for each module |
||
44 | * |
||
45 | * @param string $module |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | public function extractApiEndpoints($module) |
||
67 | |||
68 | /** |
||
69 | * Method that extract all the endpoit information by reflection |
||
70 | * |
||
71 | * @param string $namespace |
||
72 | * |
||
73 | * @return array |
||
74 | */ |
||
75 | public function extractApiInfo($namespace) |
||
104 | |||
105 | /** |
||
106 | * Extract route from doc comments |
||
107 | * |
||
108 | * @param string $comments |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | protected function extractRoute($comments = '') |
||
119 | |||
120 | /** |
||
121 | * Extract method from doc comments |
||
122 | * |
||
123 | * @param string $comments |
||
124 | * |
||
125 | * @return string |
||
126 | */ |
||
127 | protected function extractMethod($comments = '') |
||
134 | |||
135 | /** |
||
136 | * Extract visibility from doc comments |
||
137 | * |
||
138 | * @param string $comments |
||
139 | * |
||
140 | * @return boolean |
||
141 | */ |
||
142 | protected function extractVisibility($comments = '') |
||
152 | |||
153 | /** |
||
154 | * Method that extract the description for the endpoint |
||
155 | * |
||
156 | * @param string $comments |
||
157 | * |
||
158 | * @return string |
||
159 | */ |
||
160 | protected function extractDescription($comments = '') |
||
175 | |||
176 | /** |
||
177 | * Method that extract the type of a variable |
||
178 | * @param string $comments |
||
179 | * |
||
180 | * @return string |
||
181 | */ |
||
182 | protected function extractVarType($comments = '') |
||
191 | |||
192 | /** |
||
193 | * Method that extract the payload for the endpoint |
||
194 | * |
||
195 | * @param string $model |
||
196 | * @param string $comments |
||
197 | * |
||
198 | * @return array |
||
199 | */ |
||
200 | protected function extractPayload($model, $comments = '') |
||
221 | } |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.