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 |
||
9 | class ViewConfiguration |
||
10 | { |
||
11 | |||
12 | protected $request; |
||
13 | protected $response; |
||
14 | protected $layoutFile; |
||
15 | protected $viewDirectory; |
||
16 | protected $viewFile; |
||
17 | protected $jqueryUrl; |
||
18 | protected $provideWrapperHtml; |
||
19 | protected $bootstrapJsUrl; |
||
20 | protected $bootstrapCssUrl; |
||
21 | |||
22 | /** |
||
23 | * ViewConfiguration constructor. |
||
24 | * @param ServerRequestInterface $request |
||
25 | * @param MessageInterface $response |
||
26 | * @param string $viewDirectory |
||
27 | * @param string $layoutFile |
||
28 | * @param string $viewFile |
||
29 | * @param boolean $provideWrapperHtml |
||
30 | * @param boolean $provideJqueryUrl |
||
|
|||
31 | * @throws InvalidViewConfigurationException |
||
32 | */ |
||
33 | 23 | public function __construct( |
|
55 | |||
56 | /** |
||
57 | * @return mixed |
||
58 | */ |
||
59 | 9 | public function getBootstrapCssUrl() |
|
63 | |||
64 | /** |
||
65 | * @param mixed $bootstrapCssUrl |
||
66 | */ |
||
67 | 20 | public function setBootstrapCssUrl($bootstrapCssUrl) |
|
71 | |||
72 | /** |
||
73 | * @return mixed |
||
74 | */ |
||
75 | 9 | public function getBootstrapJsUrl() |
|
79 | |||
80 | /** |
||
81 | * @param mixed $bootstrapJsUrl |
||
82 | */ |
||
83 | 20 | public function setBootstrapJsUrl($bootstrapJsUrl) |
|
87 | |||
88 | |||
89 | |||
90 | /** |
||
91 | * @return mixed |
||
92 | */ |
||
93 | 9 | public function getProvideWrapperHtml() |
|
97 | |||
98 | /** |
||
99 | * @param mixed $provideWrapperHtml |
||
100 | */ |
||
101 | 20 | public function setProvideWrapperHtml($provideWrapperHtml) |
|
105 | |||
106 | /** |
||
107 | * @return ServerRequestInterface |
||
108 | */ |
||
109 | 1 | public function getRequest() |
|
113 | |||
114 | /** |
||
115 | * @param ServerRequestInterface $request |
||
116 | */ |
||
117 | 23 | public function setRequest(ServerRequestInterface $request) |
|
121 | |||
122 | /** |
||
123 | * @return ResponseInterface |
||
124 | */ |
||
125 | 1 | public function getResponse() |
|
129 | |||
130 | /** |
||
131 | * @param MessageInterface $response |
||
132 | */ |
||
133 | 23 | public function setResponse(MessageInterface $response) |
|
137 | |||
138 | /** |
||
139 | * @return string |
||
140 | */ |
||
141 | 9 | public function getLayoutFile() |
|
145 | |||
146 | /** |
||
147 | * @param string $layoutFile |
||
148 | * @throws InvalidViewConfigurationException |
||
149 | */ |
||
150 | 22 | View Code Duplication | public function setLayoutFile($layoutFile) |
158 | |||
159 | /** |
||
160 | * @return string |
||
161 | */ |
||
162 | 22 | public function getViewDirectory() |
|
166 | |||
167 | /** |
||
168 | * @param string $viewDirectory |
||
169 | * @throws InvalidViewConfigurationException |
||
170 | */ |
||
171 | 23 | public function setViewDirectory($viewDirectory) |
|
178 | |||
179 | /** |
||
180 | * @return string |
||
181 | */ |
||
182 | 1 | public function getViewFile() |
|
186 | |||
187 | /** |
||
188 | * @param string $viewFile |
||
189 | * @throws InvalidViewConfigurationException |
||
190 | */ |
||
191 | 21 | View Code Duplication | public function setViewFile($viewFile) |
199 | |||
200 | /** |
||
201 | * @return mixed |
||
202 | */ |
||
203 | 9 | public function getJqueryUrl() |
|
207 | |||
208 | /** |
||
209 | * @param mixed $jqueryUrl |
||
210 | */ |
||
211 | 20 | public function setJqueryUrl($jqueryUrl) |
|
215 | |||
216 | |||
217 | |||
218 | |||
219 | } |
||
220 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.