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 | |||
| 20 | /** |
||
| 21 | * ViewConfiguration constructor. |
||
| 22 | * @param ServerRequestInterface $request |
||
| 23 | * @param MessageInterface $response |
||
| 24 | * @param string $viewDirectory |
||
| 25 | * @param string $layoutFile |
||
| 26 | * @param string $viewFile |
||
| 27 | * @param boolean $provideWrapperHtml |
||
| 28 | * @param boolean $provideJqueryUrl |
||
|
|
|||
| 29 | * @throws InvalidViewConfigurationException |
||
| 30 | */ |
||
| 31 | public function __construct( |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return mixed |
||
| 52 | */ |
||
| 53 | public function getProvideWrapperHtml() |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param mixed $provideWrapperHtml |
||
| 60 | */ |
||
| 61 | public function setProvideWrapperHtml($provideWrapperHtml) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @return ServerRequestInterface |
||
| 68 | */ |
||
| 69 | public function getRequest() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @param ServerRequestInterface $request |
||
| 76 | */ |
||
| 77 | public function setRequest(ServerRequestInterface $request) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @return ResponseInterface |
||
| 84 | */ |
||
| 85 | public function getResponse() |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @param MessageInterface $response |
||
| 92 | */ |
||
| 93 | public function setResponse(MessageInterface $response) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @return string |
||
| 100 | */ |
||
| 101 | public function getLayoutFile() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @param string $layoutFile |
||
| 108 | * @throws InvalidViewConfigurationException |
||
| 109 | */ |
||
| 110 | View Code Duplication | public function setLayoutFile($layoutFile) |
|
| 118 | |||
| 119 | /** |
||
| 120 | * @return string |
||
| 121 | */ |
||
| 122 | public function getViewDirectory() |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @param string $viewDirectory |
||
| 129 | * @throws InvalidViewConfigurationException |
||
| 130 | */ |
||
| 131 | public function setViewDirectory($viewDirectory) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @return string |
||
| 141 | */ |
||
| 142 | public function getViewFile() |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @param string $viewFile |
||
| 149 | * @throws InvalidViewConfigurationException |
||
| 150 | */ |
||
| 151 | View Code Duplication | public function setViewFile($viewFile) |
|
| 159 | |||
| 160 | /** |
||
| 161 | * @return bool |
||
| 162 | */ |
||
| 163 | public function getJqueryUrl() |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @param bool $jqueryUrl |
||
| 170 | */ |
||
| 171 | public function setJqueryUrl($jqueryUrl) |
||
| 175 | |||
| 176 | |||
| 177 | |||
| 178 | |||
| 179 | } |
||
| 180 |
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
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.