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 ViewInfoCache */ |
||
| 54 | protected $infoCache; |
||
| 55 | |||
| 56 | /** @var string */ |
||
| 57 | protected $user; |
||
| 58 | |||
| 59 | /** @var IURLGenerator */ |
||
| 60 | protected $urlGenerator; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @param IManager $activityManager |
||
| 64 | * @param IUserManager $userManager |
||
| 65 | * @param IURLGenerator $urlGenerator |
||
| 66 | * @param IContactsManager $contactsManager |
||
| 67 | * @param ViewInfoCache $infoCache, |
||
|
|
|||
| 68 | * @param IL10N $l |
||
| 69 | * @param CurrentUser $currentUser |
||
| 70 | */ |
||
| 71 | 27 | View Code Duplication | public function __construct(IManager $activityManager, |
| 86 | |||
| 87 | /** |
||
| 88 | * @param string $user |
||
| 89 | */ |
||
| 90 | 7 | public function setUser($user) { |
|
| 93 | |||
| 94 | /** |
||
| 95 | * @param IL10N $l |
||
| 96 | */ |
||
| 97 | 5 | public function setL10n(IL10N $l) { |
|
| 100 | |||
| 101 | /** |
||
| 102 | * @param string $parameter |
||
| 103 | * @param IEvent $event |
||
| 104 | * @param string $formatter |
||
| 105 | * @return IParameter |
||
| 106 | */ |
||
| 107 | 6 | public function get($parameter, IEvent $event, $formatter) { |
|
| 108 | 6 | return new Parameter( |
|
| 109 | 6 | $parameter, |
|
| 110 | $event, |
||
| 111 | 6 | $this->getFormatter($formatter), |
|
| 112 | $formatter |
||
| 113 | ); |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @return Collection |
||
| 118 | */ |
||
| 119 | 1 | public function createCollection() { |
|
| 122 | |||
| 123 | /** |
||
| 124 | * @param string $formatter |
||
| 125 | * @return IFormatter |
||
| 126 | */ |
||
| 127 | 8 | 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.