Complex classes like IndexService 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 IndexService, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
45 | class IndexService { |
||
46 | |||
47 | /** @var IndexesRequest */ |
||
48 | private $indexesRequest; |
||
49 | |||
50 | /** @var ConfigService */ |
||
51 | private $configService; |
||
52 | |||
53 | /** @var ProviderService */ |
||
54 | private $providerService; |
||
55 | |||
56 | /** @var PlatformService */ |
||
57 | private $platformService; |
||
58 | |||
59 | /** @var MiscService */ |
||
60 | private $miscService; |
||
61 | |||
62 | |||
63 | /** @var Runner */ |
||
64 | private $runner = null; |
||
65 | |||
66 | /** @var array */ |
||
67 | private $queuedDeleteIndex = []; |
||
68 | |||
69 | |||
70 | /** |
||
71 | * IndexService constructor. |
||
72 | * |
||
73 | * @param IndexesRequest $indexesRequest |
||
74 | * @param ConfigService $configService |
||
75 | * @param ProviderService $providerService |
||
76 | * @param PlatformService $platformService |
||
77 | * @param MiscService $miscService |
||
78 | */ |
||
79 | public function __construct( |
||
90 | |||
91 | |||
92 | /** |
||
93 | * @param Runner $runner |
||
94 | */ |
||
95 | public function setRunner(Runner $runner) { |
||
98 | |||
99 | |||
100 | /** |
||
101 | * @param string $action |
||
102 | * @param bool $force |
||
103 | * |
||
104 | * @throws InterruptException |
||
105 | * @throws TickDoesNotExistException |
||
106 | */ |
||
107 | private function updateRunnerAction($action, $force = false) { |
||
114 | |||
115 | /** |
||
116 | * @param string $info |
||
117 | * @param string $value |
||
118 | */ |
||
119 | private function updateRunnerInfo($info, $value, $color = '') { |
||
126 | |||
127 | /** |
||
128 | * @param array $data |
||
129 | */ |
||
130 | private function updateRunnerInfoArray($data) { |
||
137 | |||
138 | |||
139 | /** |
||
140 | * @param IFullTextSearchPlatform $platform |
||
141 | * @param IFullTextSearchProvider $provider |
||
142 | * @param string $userId |
||
143 | * @param IndexOptions $options |
||
144 | * |
||
145 | * @throws InterruptException |
||
146 | * @throws TickDoesNotExistException |
||
147 | * @throws Exception |
||
148 | */ |
||
149 | public function indexProviderContentFromUser( |
||
181 | |||
182 | |||
183 | /** |
||
184 | * @param IFullTextSearchProvider $provider |
||
185 | * @param IndexDocument[] $documents |
||
186 | * @param IndexOptions $options |
||
187 | * |
||
188 | * @return IndexDocument[] |
||
189 | * @throws InterruptException |
||
190 | * @throws TickDoesNotExistException |
||
191 | */ |
||
192 | private function updateDocumentsWithCurrIndex( |
||
225 | |||
226 | |||
227 | /** |
||
228 | * @param IFullTextSearchProvider $provider |
||
229 | * @param IndexDocument $document |
||
230 | * |
||
231 | * @return bool |
||
232 | */ |
||
233 | private function isDocumentUpToDate(IFullTextSearchProvider $provider, IndexDocument $document |
||
247 | |||
248 | |||
249 | /** |
||
250 | * @param IFullTextSearchProvider $provider |
||
251 | * |
||
252 | * @return ProviderIndexes |
||
253 | */ |
||
254 | private function getProviderIndexFromProvider(IFullTextSearchProvider $provider) { |
||
259 | |||
260 | |||
261 | /** |
||
262 | * @param IFullTextSearchPlatform $platform |
||
263 | * @param IFullTextSearchProvider $provider |
||
264 | * @param IndexDocument[] $documents |
||
265 | * @param IndexOptions $options |
||
266 | * |
||
267 | * @throws InterruptException |
||
268 | * @throws TickDoesNotExistException |
||
269 | * @throws Exception |
||
270 | */ |
||
271 | private function indexChunks( |
||
304 | |||
305 | |||
306 | /** |
||
307 | * @param IFullTextSearchPlatform $platform |
||
308 | * @param IFullTextSearchProvider $provider |
||
309 | * @param IndexDocument[] $chunk |
||
310 | * |
||
311 | * @throws NoResultException |
||
312 | * @throws DatabaseException |
||
313 | * @throws Exception |
||
314 | */ |
||
315 | private function indexChunk( |
||
337 | |||
338 | |||
339 | /** |
||
340 | * @param IndexDocument[] $documents |
||
341 | * |
||
342 | * @return IndexDocument[] |
||
343 | */ |
||
344 | private function filterDocumentsToIndex($documents) { |
||
359 | |||
360 | |||
361 | /** |
||
362 | * @param IFullTextSearchPlatform $platform |
||
363 | * @param IFullTextSearchProvider $provider |
||
364 | * @param IndexDocument $document |
||
365 | * |
||
366 | * @return |
||
367 | * @throws Exception |
||
368 | */ |
||
369 | public function indexDocument( |
||
394 | |||
395 | |||
396 | /** |
||
397 | * @param IFullTextSearchPlatform $platform |
||
398 | * @param IFullTextSearchProvider $provider |
||
399 | * @param Index $index |
||
400 | * |
||
401 | * @internal param int|string $documentId |
||
402 | * @throws Exception |
||
403 | */ |
||
404 | public function updateDocument( |
||
428 | |||
429 | |||
430 | /** |
||
431 | * @param Index[] $indexes |
||
432 | * |
||
433 | * @throws DatabaseException |
||
434 | */ |
||
435 | public function updateIndexes($indexes) { |
||
445 | |||
446 | |||
447 | /** |
||
448 | * @param Index $index |
||
449 | * |
||
450 | * @throws Exception |
||
451 | */ |
||
452 | private function updateIndex(Index $index) { |
||
476 | |||
477 | |||
478 | private function updateIndexError(Index $index) { |
||
481 | |||
482 | |||
483 | /** |
||
484 | * @param string $providerId |
||
485 | * @param array $documentIds |
||
486 | * @param int $status |
||
487 | * @param bool $reset |
||
488 | * |
||
489 | * @throws DatabaseException |
||
490 | */ |
||
491 | public function updateIndexesStatus($providerId, $documentIds, $status, $reset = false) { |
||
510 | |||
511 | |||
512 | /** |
||
513 | * @param Index $index |
||
514 | */ |
||
515 | public function resetErrorFromIndex(Index $index) { |
||
520 | |||
521 | |||
522 | /** |
||
523 | * |
||
524 | */ |
||
525 | private function resetErrorFromQueue() { |
||
530 | |||
531 | /** |
||
532 | * |
||
533 | */ |
||
534 | public function resetErrorsAll() { |
||
537 | |||
538 | |||
539 | /** |
||
540 | * @return ExtendedIndex[] |
||
541 | */ |
||
542 | public function getErrorIndexes() { |
||
545 | |||
546 | |||
547 | /** |
||
548 | * @param string $providerId |
||
549 | * @param array $documentId |
||
550 | * |
||
551 | * @return ExtendedIndex[] |
||
552 | * @throws IndexDoesNotExistException |
||
553 | */ |
||
554 | public function getIndexes($providerId, $documentId) { |
||
557 | |||
558 | |||
559 | /** |
||
560 | * @param bool $all |
||
561 | * |
||
562 | * @return Index[] |
||
563 | */ |
||
564 | public function getQueuedIndexes($all = false) { |
||
567 | |||
568 | |||
569 | /** |
||
570 | * @param string $providerId |
||
571 | * |
||
572 | * @throws Exception |
||
573 | */ |
||
574 | public function resetIndex($providerId = '') { |
||
597 | |||
598 | |||
599 | } |