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