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 |
||
| 21 | class Server implements ServerInterface |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * a Checker instance. |
||
| 25 | * |
||
| 26 | * @var WebHelper\Parser\Parser\Checker |
||
| 27 | */ |
||
| 28 | private $checker; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * The filesystem path where the web server is installed. |
||
| 32 | * |
||
| 33 | * It has to be an absolute path. |
||
| 34 | * |
||
| 35 | * Apache httpd server does not accept a relative prefix path at compilation. |
||
| 36 | * Nginx does, but this is a very risky practice... |
||
| 37 | * So relative prefix path in nginx configuration will not be considered |
||
| 38 | * |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | private $prefix = ''; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The string to match as a starting multi-line directive. |
||
| 45 | * |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | private $startMultiLine = ''; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * The string to match as an ending multi-line directive. |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | private $endMultiLine = ''; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * The string to match a simple directive. |
||
| 59 | * |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | private $simpleDirective = ''; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * binaries that can be used to control the webserver. |
||
| 66 | * |
||
| 67 | * @var array |
||
| 68 | */ |
||
| 69 | private $binaries = []; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * the parameter string to use to detect version and config file. |
||
| 73 | * |
||
| 74 | * @var string |
||
| 75 | */ |
||
| 76 | private $detectionParameter = ''; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * The ordered list of methods to apply before convertion. |
||
| 80 | * |
||
| 81 | * @var array |
||
| 82 | */ |
||
| 83 | private $beforeMethods = []; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * The ordered list of methods to apply after convertion. |
||
| 87 | * |
||
| 88 | * @var array |
||
| 89 | */ |
||
| 90 | private $afterMethods = []; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Sets the Checker instance. |
||
| 94 | * |
||
| 95 | * @param Checker $checker a Checker instance |
||
| 96 | */ |
||
| 97 | 29 | public function setChecker(Checker $checker) |
|
| 103 | |||
| 104 | /** |
||
| 105 | * Confirms if the server instance has valid parameters. |
||
| 106 | * |
||
| 107 | * @return bool true if all parameters are initialized, false otherwise |
||
| 108 | */ |
||
| 109 | 2 | public function isValid() |
|
| 118 | |||
| 119 | /** |
||
| 120 | * Getter for the prefix. |
||
| 121 | * |
||
| 122 | * @return string the filesystem path where the web server is installed |
||
| 123 | */ |
||
| 124 | 2 | public function getPrefix() |
|
| 128 | |||
| 129 | /** |
||
| 130 | * Sets the prefix of a server instance. |
||
| 131 | * |
||
| 132 | * @throws ServerException if the prefix is invalid |
||
| 133 | * |
||
| 134 | * @param string $prefix the filesystem path where the web server is installed |
||
| 135 | */ |
||
| 136 | 11 | public function setPrefix($prefix) |
|
| 153 | |||
| 154 | /** |
||
| 155 | * Gets the regexp that will match the starting block directives. |
||
| 156 | * |
||
| 157 | * @return string the regexp that will match the starting block directives |
||
| 158 | */ |
||
| 159 | 8 | public function getStartMultiLine() |
|
| 163 | |||
| 164 | /** |
||
| 165 | * Sets the regexp that will match the starting block directives. |
||
| 166 | * |
||
| 167 | * @param string $startMultiLine the regexp that will match the starting block directives |
||
| 168 | */ |
||
| 169 | 13 | View Code Duplication | public function setStartMultiLine($startMultiLine) |
| 190 | |||
| 191 | /** |
||
| 192 | * Gets the regexp that will match the ending block directives. |
||
| 193 | * |
||
| 194 | * @return string the regexp that will match the ending block directives |
||
| 195 | */ |
||
| 196 | 8 | public function getEndMultiLine() |
|
| 200 | |||
| 201 | /** |
||
| 202 | * Sets the regexp that will match the ending block directives. |
||
| 203 | * |
||
| 204 | * @param string $endMultiLine the regexp that will match the ending block directives |
||
| 205 | */ |
||
| 206 | 10 | View Code Duplication | public function setEndMultiLine($endMultiLine) |
| 226 | |||
| 227 | /** |
||
| 228 | * Gets the regexp that will match the simple directives. |
||
| 229 | * |
||
| 230 | * @return string the regexp that will match the simple directives |
||
| 231 | */ |
||
| 232 | 8 | public function getSimpleDirective() |
|
| 236 | |||
| 237 | /** |
||
| 238 | * Sets the regexp that will match the simple directives. |
||
| 239 | * |
||
| 240 | * @param string $simpleDirective the regexp that will match the simple directives |
||
| 241 | */ |
||
| 242 | 13 | View Code Duplication | public function setSimpleDirective($simpleDirective) |
| 263 | |||
| 264 | /** |
||
| 265 | * Gets the list of binaries that can be run to analyze. |
||
| 266 | * |
||
| 267 | * @return array the list of binaries that can be run |
||
| 268 | */ |
||
| 269 | 1 | public function getBinaries() |
|
| 273 | |||
| 274 | /** |
||
| 275 | * Sets the list of binaries that can be run to analyze. |
||
| 276 | * |
||
| 277 | * @param array $binaries list of controlers |
||
| 278 | */ |
||
| 279 | 8 | public function setBinaries(array $binaries) |
|
| 285 | |||
| 286 | /** |
||
| 287 | * Sets the parameter string to use to detect version and config file. |
||
| 288 | * |
||
| 289 | * @param string $parameter parameter string |
||
| 290 | */ |
||
| 291 | 7 | public function setDetectionParameter($parameter = '') |
|
| 297 | |||
| 298 | /** |
||
| 299 | * Gets the ordered list of methods to apply before the config file turns into an array. |
||
| 300 | * |
||
| 301 | * @return array the ordered list of methods to apply before convertion |
||
| 302 | */ |
||
| 303 | 11 | public function getBeforeMethods() |
|
| 307 | |||
| 308 | /** |
||
| 309 | * Sets the ordered list of methods to apply before the config file turns into an array. |
||
| 310 | * |
||
| 311 | * @param array $methods the ordered list of methods to apply before convertion |
||
| 312 | */ |
||
| 313 | 13 | public function setBeforeMethods(array $methods) |
|
| 319 | |||
| 320 | /** |
||
| 321 | * Gets the ordered list of methods to apply after the config file has turned into an array. |
||
| 322 | * |
||
| 323 | * @return array the ordered list of methods to apply after convertion |
||
| 324 | */ |
||
| 325 | 11 | public function getAfterMethods() |
|
| 329 | |||
| 330 | /** |
||
| 331 | * Sets the ordered list of methods to apply after the config file has turned into an array. |
||
| 332 | * |
||
| 333 | * @param array $methods the ordered list of methods to apply after convertion |
||
| 334 | */ |
||
| 335 | 13 | public function setAfterMethods(array $methods) |
|
| 341 | } |
||
| 342 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..