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 ModuleContextClassGuesser implements ClassGuesserInterface |
||
12 | { |
||
13 | private $namespaceSuffix; |
||
14 | private $namespaceBase; |
||
15 | private $contextClass; |
||
16 | |||
17 | /** |
||
18 | * Initializes guesser. |
||
19 | * |
||
20 | * @param string $namespaceSuffix |
||
21 | */ |
||
22 | public function __construct($namespaceSuffix, $contextClass) |
||
27 | |||
28 | /** |
||
29 | * Sets bundle namespace to use for guessing. |
||
30 | * |
||
31 | * @param string $namespace |
||
|
|||
32 | */ |
||
33 | public function setNamespaceBase($namespaceBase) |
||
38 | |||
39 | /** |
||
40 | * Tries to guess context classname. |
||
41 | * |
||
42 | * @return string |
||
43 | */ |
||
44 | public function guess() |
||
56 | } |
||
57 |
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.