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 CirclesService { |
||
42 | |||
43 | /** @var string */ |
||
44 | private $userId; |
||
45 | |||
46 | /** @var IL10N */ |
||
47 | private $l10n; |
||
48 | |||
49 | /** @var ConfigService */ |
||
50 | private $configService; |
||
51 | |||
52 | /** @var DatabaseService */ |
||
53 | private $dbService; |
||
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( |
|
81 | |||
82 | |||
83 | /** |
||
84 | * Create circle using this->userId as owner |
||
85 | * |
||
86 | * @param int $type |
||
87 | * @param string $name |
||
88 | * |
||
89 | * @return Circle |
||
90 | * @throws CircleTypeDisabledException |
||
91 | * @throws \Exception |
||
92 | */ |
||
93 | public function createCircle($type, $name) { |
||
122 | |||
123 | |||
124 | /** |
||
125 | * list Circles depends on type (or all) and name (parts) and minimum level. |
||
126 | * |
||
127 | * @param $type |
||
128 | * @param string $name |
||
129 | * @param int $level |
||
130 | * |
||
131 | * @return array |
||
132 | * @throws CircleTypeDisabledException |
||
133 | */ |
||
134 | public function listCircles($type, $name = '', $level = 0) { |
||
150 | |||
151 | |||
152 | /** |
||
153 | * returns details on circle and its members if this->userId is a member itself. |
||
154 | * |
||
155 | * @param $circleId |
||
156 | * |
||
157 | * @return Circle |
||
158 | * @throws \Exception |
||
159 | * @internal param $circleId |
||
160 | * @internal param string $iError |
||
161 | */ |
||
162 | public function detailsCircle($circleId) { |
||
184 | |||
185 | /** |
||
186 | * Join a circle. |
||
187 | * |
||
188 | * @param $circleId |
||
189 | * |
||
190 | * @return null|Member |
||
191 | * @throws \Exception |
||
192 | */ |
||
193 | public function joinCircle($circleId) { |
||
223 | |||
224 | |||
225 | /** |
||
226 | * Leave a circle. |
||
227 | * |
||
228 | * @param $circleId |
||
229 | * |
||
230 | * @return null|Member |
||
231 | * @throws \Exception |
||
232 | */ |
||
233 | public function leaveCircle($circleId) { |
||
252 | |||
253 | |||
254 | /** |
||
255 | * destroy a circle. |
||
256 | * |
||
257 | * @param $circle |
||
258 | */ |
||
259 | public function removeCircle($circle) { |
||
266 | |||
267 | |||
268 | } |