Complex classes like CoreQueryBuilder 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 CoreQueryBuilder, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
56 | class CoreQueryBuilder extends NC22ExtendedQueryBuilder { |
||
57 | |||
58 | |||
59 | use TArrayTools; |
||
60 | |||
61 | |||
62 | const SINGLE = 'single'; |
||
63 | const CIRCLE = 'circle'; |
||
64 | const MEMBER = 'member'; |
||
65 | const MEMBER_COUNT = 'membercount'; |
||
66 | const OWNER = 'owner'; |
||
67 | const FEDERATED_EVENT = 'federatedevent'; |
||
68 | const REMOTE = 'remote'; |
||
69 | const BASED_ON = 'basedon'; |
||
70 | const INITIATOR = 'initiator'; |
||
71 | const MEMBERSHIPS = 'memberships'; |
||
72 | const CONFIG = 'config'; |
||
73 | const UPSTREAM_MEMBERSHIPS = 'upstreammemberships'; |
||
74 | const INHERITANCE_FROM = 'inheritancefrom'; |
||
75 | const INHERITED_BY = 'inheritedby'; |
||
76 | const INVITED_BY = 'invitedby'; |
||
77 | const MOUNT = 'mount'; |
||
78 | const MOUNTPOINT = 'mountpoint'; |
||
79 | const SHARE = 'share'; |
||
80 | const FILE_CACHE = 'filecache'; |
||
81 | const STORAGES = 'storages'; |
||
82 | const OPTIONS = 'options'; |
||
83 | const HELPER = 'circleshelper'; |
||
84 | |||
85 | |||
86 | public static $SQL_PATH = [ |
||
87 | self::SINGLE => [ |
||
88 | self::MEMBER |
||
89 | ], |
||
90 | self::CIRCLE => [ |
||
91 | self::OPTIONS => [ |
||
92 | ], |
||
93 | self::MEMBER, |
||
94 | self::MEMBER_COUNT, |
||
95 | self::OWNER => [ |
||
96 | self::BASED_ON |
||
97 | ], |
||
98 | self::MEMBERSHIPS => [ |
||
99 | self::CONFIG |
||
100 | ], |
||
101 | self::INITIATOR => [ |
||
102 | self::BASED_ON, |
||
103 | self::INHERITED_BY => [ |
||
104 | self::MEMBERSHIPS |
||
105 | ] |
||
106 | ], |
||
107 | self::REMOTE => [ |
||
108 | self::MEMBER, |
||
109 | self::CIRCLE => [ |
||
110 | self::OWNER |
||
111 | ] |
||
112 | ] |
||
113 | ], |
||
114 | self::MEMBER => [ |
||
115 | self::MEMBERSHIPS => [ |
||
116 | self::CONFIG |
||
117 | ], |
||
118 | self::INHERITANCE_FROM, |
||
119 | self::CIRCLE => [ |
||
120 | self::OPTIONS => [ |
||
121 | 'getData' => true |
||
122 | ], |
||
123 | self::OWNER, |
||
124 | self::MEMBERSHIPS => [ |
||
125 | self::CONFIG |
||
126 | ], |
||
127 | self::INITIATOR => [ |
||
128 | self::OPTIONS => [ |
||
129 | 'mustBeMember' => true, |
||
130 | 'canBeVisitor' => false |
||
131 | ], |
||
132 | self::BASED_ON, |
||
133 | self::INHERITED_BY => [ |
||
134 | self::MEMBERSHIPS |
||
135 | ], |
||
136 | self::INVITED_BY => [ |
||
137 | self::OWNER, |
||
138 | self::BASED_ON |
||
139 | ] |
||
140 | ] |
||
141 | ], |
||
142 | self::BASED_ON => [ |
||
143 | self::OWNER, |
||
144 | self::MEMBERSHIPS, |
||
145 | self::INITIATOR => [ |
||
146 | self::BASED_ON, |
||
147 | self::INHERITED_BY => [ |
||
148 | self::MEMBERSHIPS |
||
149 | ] |
||
150 | ] |
||
151 | ], |
||
152 | self::REMOTE => [ |
||
153 | self::MEMBER, |
||
154 | self::CIRCLE => [ |
||
155 | self::OWNER |
||
156 | ] |
||
157 | ], |
||
158 | self::INVITED_BY => [ |
||
159 | self::OWNER, |
||
160 | self::BASED_ON |
||
161 | ] |
||
162 | ], |
||
163 | self::MEMBERSHIPS => [ |
||
164 | self::CONFIG |
||
165 | ], |
||
166 | self::SHARE => [ |
||
167 | self::SHARE, |
||
168 | self::FILE_CACHE => [ |
||
169 | self::STORAGES |
||
170 | ], |
||
171 | self::UPSTREAM_MEMBERSHIPS => [ |
||
172 | self::MEMBERSHIPS, |
||
173 | self::INHERITED_BY => [ |
||
174 | self::BASED_ON |
||
175 | ], |
||
176 | self::SHARE, |
||
177 | ], |
||
178 | self::MEMBERSHIPS => [ |
||
179 | self::CONFIG |
||
180 | ], |
||
181 | self::INHERITANCE_FROM, |
||
182 | self::INHERITED_BY => [ |
||
183 | self::BASED_ON |
||
184 | ], |
||
185 | self::CIRCLE => [ |
||
186 | self::OWNER |
||
187 | ], |
||
188 | self::INITIATOR => [ |
||
189 | self::BASED_ON, |
||
190 | self::INHERITED_BY => [ |
||
191 | self::MEMBERSHIPS |
||
192 | ] |
||
193 | ] |
||
194 | ], |
||
195 | self::REMOTE => [ |
||
196 | self::MEMBER |
||
197 | ], |
||
198 | self::MOUNT => [ |
||
199 | self::MEMBER => [ |
||
200 | self::REMOTE |
||
201 | ], |
||
202 | self::INITIATOR => [ |
||
203 | self::INHERITED_BY => [ |
||
204 | self::MEMBERSHIPS |
||
205 | ] |
||
206 | ], |
||
207 | self::MOUNTPOINT, |
||
208 | self::MEMBERSHIPS => [ |
||
209 | self::CONFIG |
||
210 | ] |
||
211 | ], |
||
212 | self::HELPER => [ |
||
213 | self::MEMBERSHIPS => [ |
||
214 | self::CONFIG |
||
215 | ], |
||
216 | self::INITIATOR => [ |
||
217 | self::INHERITED_BY => [ |
||
218 | self::MEMBERSHIPS |
||
219 | ] |
||
220 | ], |
||
221 | self::CIRCLE => [ |
||
222 | self::OPTIONS => [ |
||
223 | ], |
||
224 | self::MEMBER, |
||
225 | self::OWNER => [ |
||
226 | self::BASED_ON |
||
227 | ] |
||
228 | ] |
||
229 | ] |
||
230 | ]; |
||
231 | |||
232 | |||
233 | /** @var ConfigService */ |
||
234 | private $configService; |
||
235 | |||
236 | |||
237 | /** @var array */ |
||
238 | private $options = []; |
||
239 | |||
240 | |||
241 | /** |
||
242 | * CoreQueryBuilder constructor. |
||
243 | */ |
||
244 | public function __construct() { |
||
249 | |||
250 | |||
251 | /** |
||
252 | * @param IFederatedModel $federatedModel |
||
253 | * |
||
254 | * @return string |
||
255 | */ |
||
256 | public function getInstance(IFederatedModel $federatedModel): string { |
||
261 | |||
262 | |||
263 | /** |
||
264 | * @param string $id |
||
265 | */ |
||
266 | public function limitToCircleId(string $id): void { |
||
269 | |||
270 | /** |
||
271 | * @param string $name |
||
272 | */ |
||
273 | public function limitToName(string $name): void { |
||
276 | |||
277 | /** |
||
278 | * @param string $name |
||
279 | */ |
||
280 | public function limitToDisplayName(string $name): void { |
||
283 | |||
284 | /** |
||
285 | * @param string $name |
||
286 | */ |
||
287 | public function limitToSanitizedName(string $name): void { |
||
290 | |||
291 | /** |
||
292 | * @param int $config |
||
293 | */ |
||
294 | public function limitToConfig(int $config): void { |
||
297 | |||
298 | /** |
||
299 | * @param int $source |
||
300 | */ |
||
301 | public function limitToSource(int $source): void { |
||
304 | |||
305 | /** |
||
306 | * @param int $config |
||
307 | * @param string $alias |
||
308 | */ |
||
309 | public function limitToConfigFlag(int $config, string $alias = ''): void { |
||
312 | |||
313 | |||
314 | /** |
||
315 | * @param string $singleId |
||
316 | */ |
||
317 | public function limitToSingleId(string $singleId): void { |
||
320 | |||
321 | |||
322 | /** |
||
323 | * @param string $itemId |
||
324 | */ |
||
325 | public function limitToItemId(string $itemId): void { |
||
328 | |||
329 | |||
330 | /** |
||
331 | * @param string $host |
||
332 | */ |
||
333 | public function limitToInstance(string $host): void { |
||
336 | |||
337 | |||
338 | /** |
||
339 | * @param int $userType |
||
340 | */ |
||
341 | public function limitToUserType(int $userType): void { |
||
344 | |||
345 | |||
346 | /** |
||
347 | * @param int $shareType |
||
348 | */ |
||
349 | public function limitToShareType(int $shareType): void { |
||
352 | |||
353 | |||
354 | /** |
||
355 | * @param string $shareWith |
||
356 | */ |
||
357 | public function limitToShareWith(string $shareWith): void { |
||
360 | |||
361 | |||
362 | /** |
||
363 | * @param int $nodeId |
||
364 | */ |
||
365 | public function limitToFileSource(int $nodeId): void { |
||
368 | |||
369 | /** |
||
370 | * @param array $files |
||
371 | */ |
||
372 | public function limitToFileSourceArray(array $files): void { |
||
375 | |||
376 | |||
377 | /** |
||
378 | * @param int $shareId |
||
379 | */ |
||
380 | public function limitToShareParent(int $shareId): void { |
||
383 | |||
384 | |||
385 | /** |
||
386 | * @param Circle $circle |
||
387 | */ |
||
388 | public function filterCircle(Circle $circle): void { |
||
400 | |||
401 | |||
402 | /** |
||
403 | * left join RemoteInstance based on a Member |
||
404 | */ |
||
405 | public function leftJoinRemoteInstance(string $alias): void { |
||
418 | |||
419 | |||
420 | /** |
||
421 | * @param string $alias |
||
422 | * @param RemoteInstance $remoteInstance |
||
423 | * @param bool $filterSensitiveData |
||
424 | * @param string $aliasCircle |
||
425 | * |
||
426 | * @throws RequestBuilderException |
||
427 | */ |
||
428 | public function limitToRemoteInstance( |
||
444 | |||
445 | |||
446 | /** |
||
447 | * Left join RemoteInstance based on an incoming request |
||
448 | * |
||
449 | * @param string $alias |
||
450 | * @param RemoteInstance $remoteInstance |
||
451 | * |
||
452 | * @throws RequestBuilderException |
||
453 | */ |
||
454 | public function leftJoinRemoteInstanceIncomingRequest( |
||
469 | |||
470 | |||
471 | /** |
||
472 | * left join members to check memberships of someone from instance |
||
473 | * |
||
474 | * @param string $alias |
||
475 | * @param RemoteInstance $remoteInstance |
||
476 | * @param string $aliasCircle |
||
477 | * |
||
478 | * @throws RequestBuilderException |
||
479 | */ |
||
480 | private function leftJoinMemberFromInstance( |
||
503 | |||
504 | |||
505 | /** |
||
506 | * left join circle is member of a circle from remote instance |
||
507 | * |
||
508 | * @param string $alias |
||
509 | * @param RemoteInstance $remoteInstance |
||
510 | * @param string $aliasCircle |
||
511 | * |
||
512 | * @throws RequestBuilderException |
||
513 | */ |
||
514 | private function leftJoinMemberFromRemoteCircle( |
||
550 | |||
551 | |||
552 | /** |
||
553 | * - global_scale: visibility on all Circles |
||
554 | * - trusted: visibility on all FEDERATED Circle if owner is local |
||
555 | * - external: visibility on all FEDERATED Circle if owner is local and: |
||
556 | * - with if Circle contains at least one member from the remote instance |
||
557 | * - one circle from the remote instance contains the local circle as member, and confirmed (using |
||
558 | * sync locally) |
||
559 | * - passive: like external, but the members list will only contains member from the local instance and |
||
560 | * from the remote instance. |
||
561 | * |
||
562 | * @param string $alias |
||
563 | * @param bool $sensitive |
||
564 | * @param string $aliasCircle |
||
565 | * |
||
566 | * @throws RequestBuilderException |
||
567 | */ |
||
568 | protected function limitRemoteVisibility(string $alias, bool $sensitive, string $aliasCircle) { |
||
617 | |||
618 | |||
619 | /** |
||
620 | * @param string $alias |
||
621 | * @param Member $member |
||
622 | * |
||
623 | * @throws RequestBuilderException |
||
624 | */ |
||
625 | public function limitToDirectMembership(string $alias, Member $member): void { |
||
644 | |||
645 | |||
646 | /** |
||
647 | * @param string $aliasMember |
||
648 | * @param Member $member |
||
649 | */ |
||
650 | public function filterDirectMembership(string $aliasMember, Member $member): void { |
||
691 | |||
692 | |||
693 | /** |
||
694 | * @param string $alias |
||
695 | */ |
||
696 | public function countMembers(string $alias): void { |
||
722 | |||
723 | |||
724 | /** |
||
725 | * @param string $alias |
||
726 | * @param IFederatedUser|null $initiator |
||
727 | * @param string $field |
||
728 | * @param string $helperAlias |
||
729 | * |
||
730 | * @throws RequestBuilderException |
||
731 | */ |
||
732 | public function leftJoinCircle( |
||
764 | |||
765 | |||
766 | /** |
||
767 | * @param string $aliasMember |
||
768 | * |
||
769 | * @throws RequestBuilderException |
||
770 | */ |
||
771 | public function leftJoinInvitedBy(string $aliasMember): void { |
||
791 | |||
792 | |||
793 | /** |
||
794 | * @param string $aliasMember |
||
795 | * @param IFederatedUser|null $initiator |
||
796 | * |
||
797 | * @throws RequestBuilderException |
||
798 | */ |
||
799 | public function leftJoinBasedOn( |
||
825 | |||
826 | |||
827 | /** |
||
828 | * @param string $alias |
||
829 | * @param string $field |
||
830 | * |
||
831 | * @throws RequestBuilderException |
||
832 | */ |
||
833 | public function leftJoinOwner(string $alias, string $field = 'unique_id'): void { |
||
860 | |||
861 | |||
862 | /** |
||
863 | * @param string $alias |
||
864 | * @param string $fieldCircleId |
||
865 | * @param string $fieldSingleId |
||
866 | * |
||
867 | * @throws RequestBuilderException |
||
868 | */ |
||
869 | public function leftJoinMember( |
||
902 | |||
903 | |||
904 | /** |
||
905 | * if 'getData' is true, will returns 'inheritanceBy': the Member at the end of a sub-chain of |
||
906 | * memberships (based on $field for Top Circle's singleId) |
||
907 | * |
||
908 | * @param string $alias |
||
909 | * @param string $field |
||
910 | * @param string $aliasInheritedBy |
||
911 | * |
||
912 | * @throws RequestBuilderException |
||
913 | */ |
||
914 | public function leftJoinInheritedMembers( |
||
947 | |||
948 | |||
949 | /** |
||
950 | * @throws RequestBuilderException |
||
951 | */ |
||
952 | public function limitToInheritedMemberships(string $alias, string $singleId, string $field = ''): void { |
||
968 | |||
969 | |||
970 | /** |
||
971 | * limit the request to Members and Sub Members of a Circle. |
||
972 | * |
||
973 | * @param string $alias |
||
974 | * @param string $singleId |
||
975 | * @param int $level |
||
976 | * |
||
977 | * @throws RequestBuilderException |
||
978 | */ |
||
979 | public function limitToMembersByInheritance(string $alias, string $singleId, int $level = 0): void { |
||
994 | |||
995 | |||
996 | /** |
||
997 | * if 'getData' is true, will returns 'inheritanceFrom': the Circle-As-Member of the Top Circle |
||
998 | * that explain the membership of a Member (based on $field for singleId) to a specific Circle |
||
999 | * |
||
1000 | * // TODO: returns the link/path ? |
||
1001 | * |
||
1002 | * @param string $alias |
||
1003 | * @param string $field |
||
1004 | * |
||
1005 | * @throws RequestBuilderException |
||
1006 | */ |
||
1007 | public function leftJoinMembersByInheritance(string $alias, string $field = ''): void { |
||
1035 | |||
1036 | |||
1037 | /** |
||
1038 | * limit the result to the point of view of a FederatedUser |
||
1039 | * |
||
1040 | * @param string $alias |
||
1041 | * @param IFederatedUser $user |
||
1042 | * @param string $field |
||
1043 | * @param string $helperAlias |
||
1044 | * |
||
1045 | * @return ICompositeExpression |
||
1046 | * @throws RequestBuilderException |
||
1047 | */ |
||
1048 | public function limitToInitiator( |
||
1064 | |||
1065 | |||
1066 | /** |
||
1067 | * @param string $alias |
||
1068 | */ |
||
1069 | public function leftJoinCircleConfig(string $alias): void { |
||
1086 | |||
1087 | |||
1088 | /** |
||
1089 | * Left join members to filter userId as initiator. |
||
1090 | * |
||
1091 | * @param string $alias |
||
1092 | * @param IFederatedUser $initiator |
||
1093 | * @param string $field |
||
1094 | * @param string $helperAlias |
||
1095 | * |
||
1096 | * @throws RequestBuilderException |
||
1097 | */ |
||
1098 | public function leftJoinInitiator( |
||
1175 | |||
1176 | |||
1177 | /** |
||
1178 | * @param string $alias |
||
1179 | * |
||
1180 | * @return ICompositeExpression |
||
1181 | * @throws RequestBuilderException |
||
1182 | */ |
||
1183 | protected function limitInitiatorVisibility(string $alias): ICompositeExpression { |
||
1257 | |||
1258 | |||
1259 | /** |
||
1260 | * CFG_SINGLE, CFG_HIDDEN and CFG_BACKEND means hidden from listing. |
||
1261 | * |
||
1262 | * @param string $aliasCircle |
||
1263 | * @param int $flag |
||
1264 | */ |
||
1265 | public function filterCircles( |
||
1283 | |||
1284 | |||
1285 | /** |
||
1286 | * Limit visibility on Sensitive information when search for members. |
||
1287 | * |
||
1288 | * @param string $alias |
||
1289 | * |
||
1290 | * @return ICompositeExpression |
||
1291 | */ |
||
1292 | private function limitRemoteVisibility_Sensitive_Members(string $alias): ICompositeExpression { |
||
1318 | |||
1319 | |||
1320 | /** |
||
1321 | * Link to storage/filecache |
||
1322 | * |
||
1323 | * @param string $aliasShare |
||
1324 | * |
||
1325 | * @throws RequestBuilderException |
||
1326 | */ |
||
1327 | public function leftJoinFileCache(string $aliasShare) { |
||
1354 | |||
1355 | |||
1356 | /** |
||
1357 | * @param string $aliasShare |
||
1358 | * @param string $aliasShareMemberships |
||
1359 | * |
||
1360 | * @throws RequestBuilderException |
||
1361 | */ |
||
1362 | public function leftJoinShareChild(string $aliasShare, string $aliasShareMemberships = '') { |
||
1387 | |||
1388 | |||
1389 | /** |
||
1390 | * @param string $alias |
||
1391 | * @param FederatedUser $federatedUser |
||
1392 | * @param bool $reshares |
||
1393 | */ |
||
1394 | public function limitToShareOwner(string $alias, FederatedUser $federatedUser, bool $reshares): void { |
||
1405 | |||
1406 | |||
1407 | /** |
||
1408 | * @param string $aliasMount |
||
1409 | * @param string $aliasMountMemberships |
||
1410 | * |
||
1411 | * @throws RequestBuilderException |
||
1412 | */ |
||
1413 | public function leftJoinMountpoint(string $aliasMount, string $aliasMountMemberships = '') { |
||
1432 | |||
1433 | |||
1434 | /** |
||
1435 | * @param string $alias |
||
1436 | * @param array $default |
||
1437 | * |
||
1438 | * @return CoreQueryBuilder |
||
1439 | */ |
||
1440 | private function generateCircleSelectAlias(string $alias, array $default = []): self { |
||
1450 | |||
1451 | /** |
||
1452 | * @param string $alias |
||
1453 | * @param array $default |
||
1454 | * |
||
1455 | * @return $this |
||
1456 | */ |
||
1457 | private function generateMemberSelectAlias(string $alias, array $default = []): self { |
||
1467 | |||
1468 | |||
1469 | /** |
||
1470 | * @param string $alias |
||
1471 | * @param array $default |
||
1472 | * @param string $prefix |
||
1473 | * |
||
1474 | * @return $this |
||
1475 | */ |
||
1476 | private function generateMembershipSelectAlias( |
||
1490 | |||
1491 | |||
1492 | /** |
||
1493 | * @param string $alias |
||
1494 | * @param array $default |
||
1495 | * |
||
1496 | * @return $this |
||
1497 | */ |
||
1498 | private function generateRemoteInstanceSelectAlias(string $alias, array $default = []): self { |
||
1508 | |||
1509 | |||
1510 | /** |
||
1511 | * @param array $path |
||
1512 | * @param array $options |
||
1513 | */ |
||
1514 | public function setOptions(array $path, array $options): void { |
||
1522 | |||
1523 | |||
1524 | /** |
||
1525 | * @param string $base |
||
1526 | * @param string $extension |
||
1527 | * @param array|null $options |
||
1528 | * |
||
1529 | * @return string |
||
1530 | * @throws RequestBuilderException |
||
1531 | */ |
||
1532 | public function generateAlias(string $base, string $extension, ?array &$options = []): string { |
||
1556 | |||
1557 | |||
1558 | /** |
||
1559 | * @param string $prefix |
||
1560 | * |
||
1561 | * @return array |
||
1562 | */ |
||
1563 | public function getAvailablePath(string $prefix): array { |
||
1579 | |||
1580 | } |
||
1581 | |||
1582 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.