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 |
||
| 41 | class Factory { |
||
| 42 | /** @var IManager */ |
||
| 43 | protected $activityManager; |
||
| 44 | |||
| 45 | /** @var IUserManager */ |
||
| 46 | protected $userManager; |
||
| 47 | |||
| 48 | /** @var IContactsManager */ |
||
| 49 | protected $contactsManager; |
||
| 50 | |||
| 51 | /** @var IL10N */ |
||
| 52 | protected $l; |
||
| 53 | |||
| 54 | /** @var IGroupManager */ |
||
| 55 | protected $groupManager; |
||
| 56 | |||
| 57 | /** @var ViewInfoCache */ |
||
| 58 | protected $infoCache; |
||
| 59 | |||
| 60 | /** @var string */ |
||
| 61 | protected $user; |
||
| 62 | |||
| 63 | /** @var IURLGenerator */ |
||
| 64 | protected $urlGenerator; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param IManager $activityManager |
||
| 68 | * @param IUserManager $userManager |
||
| 69 | * @param IURLGenerator $urlGenerator |
||
| 70 | * @param IContactsManager $contactsManager |
||
| 71 | * @param ViewInfoCache $infoCache, |
||
|
|
|||
| 72 | * @param IL10N $l |
||
| 73 | * @param string $user |
||
| 74 | */ |
||
| 75 | 21 | View Code Duplication | public function __construct(IManager $activityManager, |
| 92 | |||
| 93 | /** |
||
| 94 | * @param string $user |
||
| 95 | */ |
||
| 96 | 7 | public function setUser($user) { |
|
| 99 | |||
| 100 | /** |
||
| 101 | * @param IL10N $l |
||
| 102 | */ |
||
| 103 | 1 | public function setL10n(IL10N $l) { |
|
| 106 | |||
| 107 | /** |
||
| 108 | * @param string $parameter |
||
| 109 | * @param IEvent $event |
||
| 110 | * @param string $formatter |
||
| 111 | * @return IParameter |
||
| 112 | */ |
||
| 113 | 6 | public function get($parameter, IEvent $event, $formatter) { |
|
| 121 | |||
| 122 | /** |
||
| 123 | * @return Collection |
||
| 124 | */ |
||
| 125 | 1 | public function createCollection() { |
|
| 128 | |||
| 129 | /** |
||
| 130 | * @param string $formatter |
||
| 131 | * @return IFormatter |
||
| 132 | */ |
||
| 133 | 9 | protected function getFormatter($formatter) { |
|
| 146 | } |
||
| 147 |
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.