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 |
||
| 31 | abstract class Base implements IProvider { |
||
| 32 | |||
| 33 | /** @var IUserManager */ |
||
| 34 | protected $userManager; |
||
| 35 | |||
| 36 | /** @var string[] cached displayNames - key is the UID and value the displayname */ |
||
| 37 | protected $displayNames = []; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param IUserManager $userManager |
||
| 41 | */ |
||
| 42 | public function __construct(IUserManager $userManager) { |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param IEvent $event |
||
| 48 | * @param string $subject |
||
| 49 | * @param array $parameters |
||
| 50 | */ |
||
| 51 | View Code Duplication | protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
| 61 | |||
| 62 | /** |
||
| 63 | * @param array $eventData |
||
| 64 | * @return array |
||
| 65 | */ |
||
| 66 | protected function generateObjectParameter($eventData) { |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @param array $data |
||
| 80 | * @param IL10N $l |
||
| 81 | * @return array |
||
| 82 | */ |
||
| 83 | protected function generateCalendarParameter($data, IL10N $l) { |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @param int $id |
||
| 102 | * @param string $name |
||
| 103 | * @return array |
||
| 104 | */ |
||
| 105 | protected function generateLegacyCalendarParameter($id, $name) { |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @param string $id |
||
| 115 | * @return array |
||
| 116 | */ |
||
| 117 | protected function generateGroupParameter($id) { |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @param string $uid |
||
| 127 | * @return array |
||
| 128 | */ |
||
| 129 | View Code Duplication | protected function generateUserParameter($uid) { |
|
| 140 | |||
| 141 | /** |
||
| 142 | * @param string $uid |
||
| 143 | * @return string |
||
| 144 | */ |
||
| 145 | protected function getDisplayName($uid) { |
||
| 153 | } |
||
| 154 |