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 | * The string to match an inclusion directive. |
||
| 66 | * |
||
| 67 | * @var string |
||
| 68 | */ |
||
| 69 | private $inclusionDirective = ''; |
||
|
|
|||
| 70 | |||
| 71 | /** |
||
| 72 | * binaries that can be used to control the webserver. |
||
| 73 | * |
||
| 74 | * @var array |
||
| 75 | */ |
||
| 76 | private $binaries = []; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * the parameter string to use to detect version and config file. |
||
| 80 | * |
||
| 81 | * @var string |
||
| 82 | */ |
||
| 83 | private $detectionParameter = ''; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * The ordered list of methods to apply before convertion. |
||
| 87 | * |
||
| 88 | * @var array |
||
| 89 | */ |
||
| 90 | private $beforeMethods = []; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * The ordered list of methods to apply after convertion. |
||
| 94 | * |
||
| 95 | * @var array |
||
| 96 | */ |
||
| 97 | private $afterMethods = []; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * The simple directive syntax when dumped. |
||
| 101 | * |
||
| 102 | * @var string |
||
| 103 | */ |
||
| 104 | private $dumperSimpleDirective = ''; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * The starting block directive syntax when dumped. |
||
| 108 | * |
||
| 109 | * @var string |
||
| 110 | */ |
||
| 111 | private $dumperStartDirective = ''; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * The ending block directive syntax when dumped. |
||
| 115 | * |
||
| 116 | * @var string |
||
| 117 | */ |
||
| 118 | private $dumperEndDirective = ''; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * The known directives of the server |
||
| 122 | * |
||
| 123 | * @var array |
||
| 124 | */ |
||
| 125 | private $knownDirectives = []; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Sets the Checker instance. |
||
| 129 | * |
||
| 130 | * @param Checker $checker a Checker instance |
||
| 131 | */ |
||
| 132 | 30 | public function setChecker(Checker $checker) |
|
| 138 | |||
| 139 | /** |
||
| 140 | * Confirms if the server instance has valid parameters. |
||
| 141 | * |
||
| 142 | * @return bool true if all parameters are initialized, false otherwise |
||
| 143 | */ |
||
| 144 | 2 | public function isValid() |
|
| 153 | |||
| 154 | /** |
||
| 155 | * Getter for the prefix. |
||
| 156 | * |
||
| 157 | * @return string the filesystem path where the web server is installed |
||
| 158 | */ |
||
| 159 | 4 | public function getPrefix() |
|
| 163 | |||
| 164 | /** |
||
| 165 | * Sets the prefix of a server instance. |
||
| 166 | * |
||
| 167 | * |
||
| 168 | * @param string $prefix the filesystem path where the web server is installed |
||
| 169 | * |
||
| 170 | * @throws ServerException if the prefix is invalid |
||
| 171 | */ |
||
| 172 | 11 | public function setPrefix($prefix) |
|
| 189 | |||
| 190 | /** |
||
| 191 | * Gets the regexp that will match the starting block directives. |
||
| 192 | * |
||
| 193 | * @return string the regexp that will match the starting block directives |
||
| 194 | */ |
||
| 195 | 8 | public function getStartMultiLine() |
|
| 199 | |||
| 200 | /** |
||
| 201 | * Sets the regexp that will match the starting block directives. |
||
| 202 | * |
||
| 203 | * @param string $startMultiLine the regexp that will match the starting block directives |
||
| 204 | */ |
||
| 205 | 13 | public function setStartMultiLine($startMultiLine) |
|
| 218 | |||
| 219 | /** |
||
| 220 | * Gets the regexp that will match the ending block directives. |
||
| 221 | * |
||
| 222 | * @return string the regexp that will match the ending block directives |
||
| 223 | */ |
||
| 224 | 8 | public function getEndMultiLine() |
|
| 228 | |||
| 229 | /** |
||
| 230 | * Sets the regexp that will match the ending block directives. |
||
| 231 | * |
||
| 232 | * @param string $endMultiLine the regexp that will match the ending block directives |
||
| 233 | */ |
||
| 234 | 10 | public function setEndMultiLine($endMultiLine) |
|
| 244 | |||
| 245 | /** |
||
| 246 | * Gets the regexp that will match the simple directives. |
||
| 247 | * |
||
| 248 | * @return string the regexp that will match the simple directives |
||
| 249 | */ |
||
| 250 | 8 | public function getSimpleDirective() |
|
| 254 | |||
| 255 | /** |
||
| 256 | * Sets the regexp that will match the simple directives. |
||
| 257 | * |
||
| 258 | * @param string $simpleDirective the regexp that will match the simple directives |
||
| 259 | */ |
||
| 260 | 13 | public function setSimpleDirective($simpleDirective) |
|
| 273 | |||
| 274 | /** |
||
| 275 | * Sets the regular expression directive. |
||
| 276 | * |
||
| 277 | * @param string $directive the directive string |
||
| 278 | * @param string $message1 message exception if the matcher is not a string |
||
| 279 | * @param string $message2 message exception if the matcher is not a valid regex |
||
| 280 | * |
||
| 281 | * @throws ServerException if the directive matcher is invalid |
||
| 282 | * |
||
| 283 | * @return string the regular expression directive |
||
| 284 | */ |
||
| 285 | 10 | View Code Duplication | private function setRegexDirective($directive, $message1, $message2) |
| 303 | |||
| 304 | /** |
||
| 305 | * Confirms if a directive matcher is a valid regex. |
||
| 306 | * |
||
| 307 | * @param string $directive the directive matcher to check |
||
| 308 | * @param string $message1 message exception if the matcher is not a string |
||
| 309 | * @param string $message2 message exception if the matcher is not a valid regex |
||
| 310 | * |
||
| 311 | * @throws ServerException if the directive matcher is invalid |
||
| 312 | * |
||
| 313 | * @return bool true if the directive matcher is valid |
||
| 314 | */ |
||
| 315 | 19 | View Code Duplication | private function isValidDirective($directive, $message1, $message2) |
| 333 | |||
| 334 | /** |
||
| 335 | * Gets the list of binaries that can be run to analyze. |
||
| 336 | * |
||
| 337 | * @return array the list of binaries that can be run |
||
| 338 | */ |
||
| 339 | 1 | public function getBinaries() |
|
| 343 | |||
| 344 | /** |
||
| 345 | * Sets the list of binaries that can be run to analyze. |
||
| 346 | * |
||
| 347 | * @param array $binaries list of controlers |
||
| 348 | */ |
||
| 349 | 8 | public function setBinaries(array $binaries) |
|
| 355 | |||
| 356 | /** |
||
| 357 | * Gets the parameter string to use to detect version and config file. |
||
| 358 | * |
||
| 359 | * @return string parameter string |
||
| 360 | */ |
||
| 361 | 1 | public function getDetectionParameter() |
|
| 365 | |||
| 366 | /** |
||
| 367 | * Sets the parameter string to use to detect version and config file. |
||
| 368 | * |
||
| 369 | * @param string $parameter parameter string |
||
| 370 | */ |
||
| 371 | 8 | public function setDetectionParameter($parameter = '') |
|
| 377 | |||
| 378 | /** |
||
| 379 | * Gets the ordered list of methods to apply before the config file turns into an array. |
||
| 380 | * |
||
| 381 | * @return array the ordered list of methods to apply before convertion |
||
| 382 | */ |
||
| 383 | 14 | public function getBeforeMethods() |
|
| 387 | |||
| 388 | /** |
||
| 389 | * Sets the ordered list of methods to apply before the config file turns into an array. |
||
| 390 | * |
||
| 391 | * @param array $methods the ordered list of methods to apply before convertion |
||
| 392 | */ |
||
| 393 | 13 | public function setBeforeMethods(array $methods) |
|
| 399 | |||
| 400 | /** |
||
| 401 | * Gets the ordered list of methods to apply after the config file has turned into an array. |
||
| 402 | * |
||
| 403 | * @return array the ordered list of methods to apply after convertion |
||
| 404 | */ |
||
| 405 | 14 | public function getAfterMethods() |
|
| 409 | |||
| 410 | /** |
||
| 411 | * Sets the ordered list of methods to apply after the config file has turned into an array. |
||
| 412 | * |
||
| 413 | * @param array $methods the ordered list of methods to apply after convertion |
||
| 414 | */ |
||
| 415 | 13 | public function setAfterMethods(array $methods) |
|
| 421 | |||
| 422 | /** |
||
| 423 | * Gets the simple directive syntax when dumped. |
||
| 424 | * |
||
| 425 | * @return string the simple directive syntax when dumped |
||
| 426 | */ |
||
| 427 | 1 | public function getDumperSimpleDirective() |
|
| 431 | |||
| 432 | /** |
||
| 433 | * Gets the starting block directive syntax when dumped. |
||
| 434 | * |
||
| 435 | * @return string the starting block directive syntax when dumped |
||
| 436 | */ |
||
| 437 | 1 | public function getDumperStartDirective() |
|
| 441 | |||
| 442 | /** |
||
| 443 | * Gets the ending block directive syntax when dumped. |
||
| 444 | * |
||
| 445 | * @return string the ending block directive syntax when dumped |
||
| 446 | */ |
||
| 447 | 1 | public function getDumperEndDirective() |
|
| 451 | |||
| 452 | /** |
||
| 453 | * Sets the simple directive syntax when dumped. |
||
| 454 | * |
||
| 455 | * @param string $simpleDirective the simple directive syntax when dumped |
||
| 456 | */ |
||
| 457 | 8 | public function setDumperSimpleDirective($simpleDirective) |
|
| 463 | |||
| 464 | /** |
||
| 465 | * Sets the starting block directive syntax when dumped. |
||
| 466 | * |
||
| 467 | * @param string $startMultiLine the starting block directive syntax when dumped |
||
| 468 | */ |
||
| 469 | 8 | public function setDumperStartDirective($startMultiLine) |
|
| 475 | |||
| 476 | /** |
||
| 477 | * Sets the ending block directive syntax when dumped. |
||
| 478 | * |
||
| 479 | * @param string $endMultiLine the ending block directive syntax when dumped |
||
| 480 | */ |
||
| 481 | 8 | public function setDumperEndDirective($endMultiLine) |
|
| 487 | |||
| 488 | /** |
||
| 489 | * Gets the known directives of the server. |
||
| 490 | * |
||
| 491 | * @return array the known directives of the server |
||
| 492 | */ |
||
| 493 | 9 | public function getKnownDirectives() |
|
| 497 | |||
| 498 | /** |
||
| 499 | * Sets the known directives of the server. |
||
| 500 | * |
||
| 501 | * @param array $knownDirectives the known directives of the server |
||
| 502 | */ |
||
| 503 | 7 | public function setKnownDirectives(array $knownDirectives) |
|
| 509 | } |
||
| 510 |
This check marks private properties in classes that are never used. Those properties can be removed.