Complex classes like DeprecatedRequestBuilder often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DeprecatedRequestBuilder, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
22 | class DeprecatedRequestBuilder { |
||
23 | |||
24 | const TABLE_FILE_SHARES = 'share'; |
||
25 | const SHARE_TYPE = 7; |
||
26 | |||
27 | const TABLE_CIRCLES = 'circle_circles'; |
||
28 | const TABLE_MEMBERS = 'circle_members'; |
||
29 | const TABLE_GROUPS = 'circle_groups'; |
||
30 | const TABLE_SHARES = 'circle_shares'; |
||
31 | const TABLE_LINKS = 'circle_links'; |
||
32 | const TABLE_TOKENS = 'circle_tokens'; |
||
33 | const TABLE_GSEVENTS = 'circle_gsevents'; |
||
34 | const TABLE_GSSHARES = 'circle_gsshares'; |
||
35 | const TABLE_GSSHARES_MOUNTPOINT = 'circle_gsshares_mp'; |
||
36 | const TABLE_REMOTE = 'circle_remotes'; |
||
37 | |||
38 | const NC_TABLE_ACCOUNTS = 'accounts'; |
||
39 | const NC_TABLE_GROUP_USER = 'group_user'; |
||
40 | |||
41 | /** @var array */ |
||
42 | private $tables = [ |
||
43 | self::TABLE_CIRCLES, |
||
44 | self::TABLE_GROUPS, |
||
45 | self::TABLE_MEMBERS, |
||
46 | self::TABLE_SHARES, |
||
47 | self::TABLE_LINKS, |
||
48 | self::TABLE_TOKENS, |
||
49 | self::TABLE_GSEVENTS, |
||
50 | self::TABLE_GSSHARES, |
||
51 | self::TABLE_GSSHARES_MOUNTPOINT |
||
52 | ]; |
||
53 | |||
54 | |||
55 | /** @var IDBConnection */ |
||
56 | protected $dbConnection; |
||
57 | |||
58 | /** @var IL10N */ |
||
59 | protected $l10n; |
||
60 | |||
61 | /** @var ConfigService */ |
||
62 | protected $configService; |
||
63 | |||
64 | /** @var TimezoneService */ |
||
65 | protected $timezoneService; |
||
66 | |||
67 | /** @var MiscService */ |
||
68 | protected $miscService; |
||
69 | |||
70 | /** @var string */ |
||
71 | protected $default_select_alias; |
||
72 | |||
73 | /** @var bool */ |
||
74 | protected $leftJoinedNCGroupAndUser = false; |
||
75 | |||
76 | |||
77 | /** |
||
78 | * CoreQueryBuilder constructor. |
||
79 | * |
||
80 | * @param IL10N $l10n |
||
81 | * @param IDBConnection $connection |
||
82 | * @param ConfigService $configService |
||
83 | * @param TimezoneService $timezoneService |
||
84 | * @param MiscService $miscService |
||
85 | */ |
||
86 | public function __construct( |
||
96 | |||
97 | |||
98 | /** |
||
99 | * Limit the request by its Id. |
||
100 | * |
||
101 | * @param IQueryBuilder $qb |
||
102 | * @param int $id |
||
103 | */ |
||
104 | protected function limitToId(IQueryBuilder $qb, $id) { |
||
107 | |||
108 | |||
109 | /** |
||
110 | * Limit the request by its UniqueId. |
||
111 | * |
||
112 | * @param IQueryBuilder $qb |
||
113 | * @param int $uniqueId |
||
114 | */ |
||
115 | protected function limitToUniqueId(IQueryBuilder $qb, $uniqueId) { |
||
118 | |||
119 | |||
120 | /** |
||
121 | * Limit the request by its addressbookId. |
||
122 | * |
||
123 | * @param IQueryBuilder $qb |
||
124 | * @param int $bookId |
||
125 | */ |
||
126 | protected function limitToAddressBookId(IQueryBuilder $qb, $bookId) { |
||
129 | |||
130 | |||
131 | /** |
||
132 | * Limit the request by its addressbookId. |
||
133 | * |
||
134 | * @param IQueryBuilder $qb |
||
135 | * @param string $groupName |
||
136 | */ |
||
137 | protected function limitToContactGroup(IQueryBuilder $qb, $groupName) { |
||
140 | |||
141 | |||
142 | /** |
||
143 | * Limit the request to the Circle by its Id. |
||
144 | * |
||
145 | * @param IQueryBuilder $qb |
||
146 | * @param string $contactId |
||
147 | */ |
||
148 | protected function limitToContactId(IQueryBuilder $qb, $contactId) { |
||
151 | |||
152 | |||
153 | /** |
||
154 | * Limit the request by its Token. |
||
155 | * |
||
156 | * @param IQueryBuilder $qb |
||
157 | * @param string $token |
||
158 | */ |
||
159 | protected function limitToToken(IQueryBuilder $qb, $token) { |
||
162 | |||
163 | |||
164 | /** |
||
165 | * Limit the request to the User by its Id. |
||
166 | * |
||
167 | * @param IQueryBuilder $qb |
||
168 | * @param $userId |
||
169 | */ |
||
170 | protected function limitToUserId(IQueryBuilder $qb, $userId) { |
||
173 | |||
174 | |||
175 | /** |
||
176 | * Limit the request to the owner |
||
177 | * |
||
178 | * @param IQueryBuilder $qb |
||
179 | * @param $owner |
||
180 | */ |
||
181 | protected function limitToOwner(IQueryBuilder $qb, $owner) { |
||
184 | |||
185 | |||
186 | /** |
||
187 | * Limit the request to the Member by its Id. |
||
188 | * |
||
189 | * @param IQueryBuilder $qb |
||
190 | * @param string $memberId |
||
191 | */ |
||
192 | protected function limitToMemberId(IQueryBuilder $qb, string $memberId) { |
||
195 | |||
196 | |||
197 | /** |
||
198 | * Limit the request to the Type entry. |
||
199 | * |
||
200 | * @param IQueryBuilder $qb |
||
201 | * @param int $type |
||
202 | */ |
||
203 | protected function limitToUserType(IQueryBuilder $qb, $type) { |
||
206 | |||
207 | |||
208 | /** |
||
209 | * Limit the request to the Instance. |
||
210 | * |
||
211 | * @param IQueryBuilder $qb |
||
212 | * @param string $instance |
||
213 | */ |
||
214 | protected function limitToInstance(IQueryBuilder $qb, string $instance) { |
||
217 | |||
218 | |||
219 | /** |
||
220 | * Limit the request to the Circle by its Id. |
||
221 | * |
||
222 | * @param IQueryBuilder $qb |
||
223 | * @param string $circleUniqueId |
||
224 | */ |
||
225 | protected function limitToCircleId(IQueryBuilder $qb, $circleUniqueId) { |
||
228 | |||
229 | |||
230 | /** |
||
231 | * Limit the request to the Circle by its Id. |
||
232 | * |
||
233 | * @param IQueryBuilder $qb |
||
234 | * @param int $shareId |
||
235 | */ |
||
236 | protected function limitToShareId(IQueryBuilder $qb, int $shareId) { |
||
239 | |||
240 | |||
241 | /** |
||
242 | * Limit the request to the Circle by its Id. |
||
243 | * |
||
244 | * @param IQueryBuilder $qb |
||
245 | * @param string $mountpoint |
||
246 | */ |
||
247 | protected function limitToMountpoint(IQueryBuilder $qb, string $mountpoint) { |
||
250 | |||
251 | /** |
||
252 | * Limit the request to the Circle by its Id. |
||
253 | * |
||
254 | * @param IQueryBuilder $qb |
||
255 | * @param string $hash |
||
256 | */ |
||
257 | protected function limitToMountpointHash(IQueryBuilder $qb, string $hash) { |
||
260 | |||
261 | // |
||
262 | // /** |
||
263 | // * Limit the request to the Circle by its Shorten Unique Id. |
||
264 | // * |
||
265 | // * @param IQueryBuilder $qb |
||
266 | // * @param string $circleUniqueId |
||
267 | // * @param $length |
||
268 | // */ |
||
269 | // protected function limitToShortenUniqueId(IQueryBuilder $qb, $circleUniqueId, $length) { |
||
270 | // $expr = $qb->expr(); |
||
271 | // $pf = ($qb->getType() === QueryBuilder::SELECT) ? '`' . $this->default_select_alias . '`.' : ''; |
||
272 | // |
||
273 | // $qb->andWhere( |
||
274 | // $expr->eq( |
||
275 | // $qb->createNamedParameter($circleUniqueId), |
||
276 | // $qb->createFunction('SUBSTR(' . $pf . '`unique_id`' . ', 1, ' . $length . ')') |
||
277 | // ) |
||
278 | // ); |
||
279 | // |
||
280 | // } |
||
281 | |||
282 | |||
283 | /** |
||
284 | * Limit the request to the Group by its Id. |
||
285 | * |
||
286 | * @param IQueryBuilder $qb |
||
287 | * @param int $groupId |
||
288 | */ |
||
289 | protected function limitToGroupId(IQueryBuilder $qb, $groupId) { |
||
292 | |||
293 | |||
294 | /** |
||
295 | * Limit the search by its Name |
||
296 | * |
||
297 | * @param IQueryBuilder $qb |
||
298 | * @param string $name |
||
299 | */ |
||
300 | protected function limitToName(IQueryBuilder $qb, $name) { |
||
303 | |||
304 | |||
305 | /** |
||
306 | * Limit the search by its Status (or greater) |
||
307 | * |
||
308 | * @param IQueryBuilder $qb |
||
309 | * @param string $name |
||
310 | */ |
||
311 | protected function limitToStatus(IQueryBuilder $qb, $name) { |
||
314 | |||
315 | |||
316 | /** |
||
317 | * Limit the request by its Id. |
||
318 | * |
||
319 | * @param IQueryBuilder $qb |
||
320 | * @param string $type |
||
321 | */ |
||
322 | protected function limitToShareType(IQueryBuilder $qb, string $type) { |
||
325 | |||
326 | |||
327 | /** |
||
328 | * Limit the request by its Id. |
||
329 | * |
||
330 | * @param IQueryBuilder $qb |
||
331 | * @param string $with |
||
332 | */ |
||
333 | protected function limitToShareWith(IQueryBuilder $qb, string $with) { |
||
336 | |||
337 | |||
338 | /** |
||
339 | * Limit the request to a minimum member level. |
||
340 | * |
||
341 | * if $pf is an array, will generate an SQL OR request to limit level in multiple tables |
||
342 | * |
||
343 | * @param IQueryBuilder $qb |
||
344 | * @param int $level |
||
345 | * @param string|array $pf |
||
346 | */ |
||
347 | protected function limitToLevel(IQueryBuilder $qb, int $level, $pf = '') { |
||
364 | |||
365 | |||
366 | /** |
||
367 | * @param IQueryBuilder $qb |
||
368 | * @param int $level |
||
369 | * @param array $pf |
||
370 | * |
||
371 | * @return mixed |
||
372 | */ |
||
373 | private function generateLimitToLevelMultipleTableRequest(IQueryBuilder $qb, int $level, $pf) { |
||
386 | |||
387 | |||
388 | /** |
||
389 | * Limit the search to Members and Almost members |
||
390 | * |
||
391 | * @param IQueryBuilder $qb |
||
392 | */ |
||
393 | protected function limitToMembersAndAlmost(IQueryBuilder $qb) { |
||
405 | |||
406 | |||
407 | /** |
||
408 | * @param IQueryBuilder $qb |
||
409 | * @param string $field |
||
410 | * @param string|integer $value |
||
411 | */ |
||
412 | public function limitToDBField(IQueryBuilder $qb, $field, $value) { |
||
417 | |||
418 | |||
419 | /** |
||
420 | * @param IQueryBuilder $qb |
||
421 | * @param string $field |
||
422 | * @param string|integer $value |
||
423 | */ |
||
424 | private function limitToDBFieldOrGreater(IQueryBuilder $qb, $field, $value) { |
||
429 | |||
430 | |||
431 | /** |
||
432 | * link to the groupId/UserId of the NC DB. |
||
433 | * If userId is empty, we add the uid of the NCGroup Table in the select list with 'user_id' |
||
434 | * alias |
||
435 | * |
||
436 | * @param IQueryBuilder $qb |
||
437 | * @param string $userId |
||
438 | */ |
||
439 | protected function limitToNCGroupUser(IQueryBuilder $qb, $userId = '') { |
||
454 | |||
455 | |||
456 | /** |
||
457 | * Left Join circle table to get more information about the circle. |
||
458 | * |
||
459 | * @param IQueryBuilder $qb |
||
460 | */ |
||
461 | protected function leftJoinCircle(IQueryBuilder $qb) { |
||
479 | |||
480 | |||
481 | /** |
||
482 | * link to the groupId/UserId of the NC DB. |
||
483 | * |
||
484 | * @param IQueryBuilder $qb |
||
485 | * @param string $userId |
||
486 | * @param string $field |
||
487 | * |
||
488 | * @throws GSStatusException |
||
489 | */ |
||
490 | protected function leftJoinNCGroupAndUser(IQueryBuilder $qb, $userId, $field) { |
||
514 | |||
515 | } |
||
516 | |||
519 |