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 |
||
| 38 | class CirclesService { |
||
| 39 | |||
| 40 | /** @var string */ |
||
| 41 | private $userId; |
||
| 42 | |||
| 43 | /** @var IL10N */ |
||
| 44 | private $l10n; |
||
| 45 | |||
| 46 | /** @var ConfigService */ |
||
| 47 | private $configService; |
||
| 48 | |||
| 49 | /** @var CirclesMapper */ |
||
| 50 | private $dbCircles; |
||
| 51 | |||
| 52 | /** @var MembersMapper */ |
||
| 53 | private $dbMembers; |
||
| 54 | |||
| 55 | /** @var MiscService */ |
||
| 56 | private $miscService; |
||
| 57 | |||
| 58 | |||
| 59 | /** |
||
| 60 | * CirclesService constructor. |
||
| 61 | * |
||
| 62 | * @param $userId |
||
| 63 | * @param IL10N $l10n |
||
| 64 | * @param ConfigService $configService |
||
| 65 | * @param DatabaseService $databaseService |
||
| 66 | * @param MiscService $miscService |
||
| 67 | */ |
||
| 68 | View Code Duplication | public function __construct( |
|
| 83 | |||
| 84 | |||
| 85 | /** |
||
| 86 | * Create circle using this->userId as owner |
||
| 87 | * |
||
| 88 | * @param int $type |
||
| 89 | * @param string $name |
||
| 90 | * |
||
| 91 | * @return Circle |
||
| 92 | * @throws CircleTypeDisabledException |
||
| 93 | * @throws \Exception |
||
| 94 | */ |
||
| 95 | public function createCircle($type, $name) { |
||
| 119 | |||
| 120 | |||
| 121 | /** |
||
| 122 | * list Circles depends on type (or all) and name (parts) and minimum level. |
||
| 123 | * |
||
| 124 | * @param $type |
||
| 125 | * @param string $name |
||
| 126 | * @param int $level |
||
| 127 | * |
||
| 128 | * @return array |
||
| 129 | * @throws CircleTypeDisabledException |
||
| 130 | */ |
||
| 131 | public function listCircles($type, $name = '', $level = 0) { |
||
| 148 | |||
| 149 | |||
| 150 | /** |
||
| 151 | * returns details on circle and its members if this->userId is a member itself. |
||
| 152 | * |
||
| 153 | * @param $circleId |
||
| 154 | * |
||
| 155 | * @return Circle |
||
| 156 | * @throws \Exception |
||
| 157 | * @internal param $circleId |
||
| 158 | * @internal param string $iError |
||
| 159 | */ |
||
| 160 | public function detailsCircle($circleId) { |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Join a circle. |
||
| 182 | * |
||
| 183 | * @param $circleId |
||
| 184 | * |
||
| 185 | * @return null|Member |
||
| 186 | * @throws \Exception |
||
| 187 | */ |
||
| 188 | View Code Duplication | public function joinCircle($circleId) { |
|
| 210 | |||
| 211 | |||
| 212 | /** |
||
| 213 | * Leave a circle. |
||
| 214 | * |
||
| 215 | * @param $circleId |
||
| 216 | * |
||
| 217 | * @return null|Member |
||
| 218 | * @throws \Exception |
||
| 219 | */ |
||
| 220 | public function leaveCircle($circleId) { |
||
| 241 | |||
| 242 | |||
| 243 | /** |
||
| 244 | * destroy a circle. |
||
| 245 | * |
||
| 246 | * @param int $circleId |
||
| 247 | * |
||
| 248 | * @throws MemberIsNotOwnerException |
||
| 249 | */ |
||
| 250 | public function removeCircle($circleId) { |
||
| 263 | |||
| 264 | |||
| 265 | /** |
||
| 266 | * Convert a Type in String to its Bit Value |
||
| 267 | * |
||
| 268 | * @param $type |
||
| 269 | * |
||
| 270 | * @return int |
||
|
|
|||
| 271 | */ |
||
| 272 | public static function convertTypeStringToBitValue(& $type) { |
||
| 289 | |||
| 290 | } |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.