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 |
||
37 | class CirclesService { |
||
38 | |||
39 | /** @var string */ |
||
40 | private $userId; |
||
41 | |||
42 | /** @var IL10N */ |
||
43 | private $l10n; |
||
44 | |||
45 | /** @var ConfigService */ |
||
46 | private $configService; |
||
47 | |||
48 | /** @var CirclesMapper */ |
||
49 | private $dbCircles; |
||
50 | |||
51 | /** @var MembersMapper */ |
||
52 | private $dbMembers; |
||
53 | |||
54 | /** @var MiscService */ |
||
55 | private $miscService; |
||
56 | |||
57 | |||
58 | /** |
||
59 | * CirclesService constructor. |
||
60 | * |
||
61 | * @param $userId |
||
62 | * @param IL10N $l10n |
||
63 | * @param ConfigService $configService |
||
64 | * @param DatabaseService $databaseService |
||
65 | * @param MiscService $miscService |
||
66 | */ |
||
67 | View Code Duplication | public function __construct( |
|
82 | |||
83 | |||
84 | /** |
||
85 | * Create circle using this->userId as owner |
||
86 | * |
||
87 | * @param int $type |
||
88 | * @param string $name |
||
89 | * |
||
90 | * @return Circle |
||
91 | * @throws CircleTypeDisabledException |
||
92 | * @throws \Exception |
||
93 | */ |
||
94 | public function createCircle($type, $name) { |
||
115 | |||
116 | |||
117 | /** |
||
118 | * list Circles depends on type (or all) and name (parts) and minimum level. |
||
119 | * |
||
120 | * @param $type |
||
121 | * @param string $name |
||
122 | * @param int $level |
||
123 | * |
||
124 | * @return array |
||
125 | * @throws CircleTypeDisabledException |
||
126 | */ |
||
127 | public function listCircles($type, $name = '', $level = 0) { |
||
142 | |||
143 | |||
144 | /** |
||
145 | * returns details on circle and its members if this->userId is a member itself. |
||
146 | * |
||
147 | * @param $circleId |
||
148 | * |
||
149 | * @return Circle |
||
150 | * @throws \Exception |
||
151 | * @internal param $circleId |
||
152 | * @internal param string $iError |
||
153 | */ |
||
154 | public function detailsCircle($circleId) { |
||
173 | |||
174 | /** |
||
175 | * Join a circle. |
||
176 | * |
||
177 | * @param $circleId |
||
178 | * |
||
179 | * @return null|Member |
||
180 | * @throws \Exception |
||
181 | */ |
||
182 | public function joinCircle($circleId) { |
||
204 | |||
205 | |||
206 | /** |
||
207 | * Leave a circle. |
||
208 | * |
||
209 | * @param $circleId |
||
210 | * |
||
211 | * @return null|Member |
||
212 | * @throws \Exception |
||
213 | */ |
||
214 | public function leaveCircle($circleId) { |
||
231 | |||
232 | |||
233 | /** |
||
234 | * destroy a circle. |
||
235 | * |
||
236 | * @param $circle |
||
237 | */ |
||
238 | public function removeCircle($circle) { |
||
242 | |||
243 | |||
244 | } |