Complex classes like Typo3PageIndexer 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 Typo3PageIndexer, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 46 | class Typo3PageIndexer  | 
            ||
| 47 | { | 
            ||
| 48 | |||
| 49 | /**  | 
            ||
| 50 | * ID of the current page's Solr document.  | 
            ||
| 51 | *  | 
            ||
| 52 | * @var string  | 
            ||
| 53 | */  | 
            ||
| 54 | protected static $pageSolrDocumentId = '';  | 
            ||
| 55 | /**  | 
            ||
| 56 | * The Solr document generated for the current page.  | 
            ||
| 57 | *  | 
            ||
| 58 | * @var \Apache_Solr_Document  | 
            ||
| 59 | */  | 
            ||
| 60 | protected static $pageSolrDocument = null;  | 
            ||
| 61 | /**  | 
            ||
| 62 | * The mount point parameter used in the Frontend controller.  | 
            ||
| 63 | *  | 
            ||
| 64 | * @var string  | 
            ||
| 65 | */  | 
            ||
| 66 | protected $mountPointParameter;  | 
            ||
| 67 | /**  | 
            ||
| 68 | * Solr server connection.  | 
            ||
| 69 | *  | 
            ||
| 70 | * @var SolrService  | 
            ||
| 71 | */  | 
            ||
| 72 | protected $solrConnection = null;  | 
            ||
| 73 | /**  | 
            ||
| 74 | * Frontend page object (TSFE).  | 
            ||
| 75 | *  | 
            ||
| 76 | * @var TypoScriptFrontendController  | 
            ||
| 77 | */  | 
            ||
| 78 | protected $page = null;  | 
            ||
| 79 | /**  | 
            ||
| 80 | * Content extractor to extract content from TYPO3 pages  | 
            ||
| 81 | *  | 
            ||
| 82 | * @var Typo3PageContentExtractor  | 
            ||
| 83 | */  | 
            ||
| 84 | protected $contentExtractor = null;  | 
            ||
| 85 | /**  | 
            ||
| 86 | * URL to be indexed as the page's URL  | 
            ||
| 87 | *  | 
            ||
| 88 | * @var string  | 
            ||
| 89 | */  | 
            ||
| 90 | protected $pageUrl = '';  | 
            ||
| 91 | /**  | 
            ||
| 92 | * The page's access rootline  | 
            ||
| 93 | *  | 
            ||
| 94 | * @var Rootline  | 
            ||
| 95 | */  | 
            ||
| 96 | protected $pageAccessRootline = null;  | 
            ||
| 97 | /**  | 
            ||
| 98 | * Documents that have been sent to Solr  | 
            ||
| 99 | *  | 
            ||
| 100 | * @var array  | 
            ||
| 101 | */  | 
            ||
| 102 | protected $documentsSentToSolr = [];  | 
            ||
| 103 | |||
| 104 | /**  | 
            ||
| 105 | * @var TypoScriptConfiguration  | 
            ||
| 106 | */  | 
            ||
| 107 | protected $configuration;  | 
            ||
| 108 | |||
| 109 | /**  | 
            ||
| 110 | * @var Item  | 
            ||
| 111 | */  | 
            ||
| 112 | protected $indexQueueItem;  | 
            ||
| 113 | |||
| 114 | /**  | 
            ||
| 115 | * @var \ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager  | 
            ||
| 116 | */  | 
            ||
| 117 | protected $logger = null;  | 
            ||
| 118 | |||
| 119 | /**  | 
            ||
| 120 | * Constructor  | 
            ||
| 121 | *  | 
            ||
| 122 | * @param TypoScriptFrontendController $page The page to index  | 
            ||
| 123 | */  | 
            ||
| 124 | public function __construct(TypoScriptFrontendController $page)  | 
            ||
| 154 | |||
| 155 | /**  | 
            ||
| 156 | * @param Item $indexQueueItem  | 
            ||
| 157 | 44 | */  | 
            |
| 158 | 44 | public function setIndexQueueItem($indexQueueItem)  | 
            |
| 162 | |||
| 163 | /**  | 
            ||
| 164 | * Initializes the Solr server connection.  | 
            ||
| 165 | 6 | *  | 
            |
| 166 | * @throws \Exception when no Solr connection can be established.  | 
            ||
| 167 | 6 | */  | 
            |
| 168 | 6 | protected function initializeSolrConnection()  | 
            |
| 182 | |||
| 183 | /**  | 
            ||
| 184 | * Gets the current page's Solr document ID.  | 
            ||
| 185 | *  | 
            ||
| 186 | * @return string|NULL The page's Solr document ID or NULL in case no document was generated yet.  | 
            ||
| 187 | */  | 
            ||
| 188 | 44 | public static function getPageSolrDocumentId()  | 
            |
| 192 | |||
| 193 | /**  | 
            ||
| 194 | * Gets the Solr document generated for the current page.  | 
            ||
| 195 | *  | 
            ||
| 196 | * @return \Apache_Solr_Document|NULL The page's Solr document or NULL if it has not been generated yet.  | 
            ||
| 197 | */  | 
            ||
| 198 | public static function getPageSolrDocument()  | 
            ||
| 202 | |||
| 203 | /**  | 
            ||
| 204 | * Allows to provide a Solr server connection other than the one  | 
            ||
| 205 | * initialized by the constructor.  | 
            ||
| 206 | 6 | *  | 
            |
| 207 | * @param SolrService $solrConnection Solr connection  | 
            ||
| 208 | 6 | * @throws \Exception if the Solr server cannot be reached  | 
            |
| 209 | */  | 
            ||
| 210 | public function setSolrConnection(SolrService $solrConnection)  | 
            ||
| 221 | |||
| 222 | /**  | 
            ||
| 223 | * Indexes a page.  | 
            ||
| 224 | *  | 
            ||
| 225 | * @return bool TRUE after successfully indexing the page, FALSE on error  | 
            ||
| 226 | * @throws \UnexpectedValueException if a page document post processor fails to implement interface ApacheSolrForTypo3\Solr\PageDocumentPostProcessor  | 
            ||
| 227 | 6 | */  | 
            |
| 228 | 6 | public function indexPage()  | 
            |
| 256 | 44 | ||
| 257 | 44 | /**  | 
            |
| 258 | * Applies the configured post processors (indexPagePostProcessPageDocument)  | 
            ||
| 259 | 44 | *  | 
            |
| 260 | 44 | * @param \Apache_Solr_Document $pageDocument  | 
            |
| 261 | */  | 
            ||
| 262 | 44 | protected function applyIndexPagePostProcessors($pageDocument)  | 
            |
| 277 | 1 | ||
| 278 | 1 | /**  | 
            |
| 279 | * Builds the Solr document for the current page.  | 
            ||
| 280 | *  | 
            ||
| 281 | * @return \Apache_Solr_Document A document representing the page  | 
            ||
| 282 | 1 | */  | 
            |
| 283 | protected function getPageDocument()  | 
            ||
| 293 | 44 | ||
| 294 | |||
| 295 | 44 | // Logging  | 
            |
| 296 | 44 | // TODO replace by a central logger  | 
            |
| 297 | |||
| 298 | 44 | /**  | 
            |
| 299 | 44 | * Gets the mount point parameter that is used in the Frontend controller.  | 
            |
| 300 | 44 | *  | 
            |
| 301 | 44 | * @return string  | 
            |
| 302 | 44 | */  | 
            |
| 303 | 44 | public function getMountPointParameter()  | 
            |
| 307 | 44 | ||
| 308 | 44 | // Misc  | 
            |
| 309 | 44 | ||
| 310 | /**  | 
            ||
| 311 | * Sets the mount point parameter that is used in the Frontend controller.  | 
            ||
| 312 | 44 | *  | 
            |
| 313 | 44 | * @param string $mountPointParameter  | 
            |
| 314 | */  | 
            ||
| 315 | public function setMountPointParameter($mountPointParameter)  | 
            ||
| 319 | 44 | ||
| 320 | 44 | /**  | 
            |
| 321 | 44 | * Allows third party extensions to replace or modify the page document  | 
            |
| 322 | * created by this indexer.  | 
            ||
| 323 | 44 | *  | 
            |
| 324 | 44 | * @param \Apache_Solr_Document $pageDocument The page document created by this indexer.  | 
            |
| 325 | * @return \Apache_Solr_Document An Apache Solr document representing the currently indexed page  | 
            ||
| 326 | */  | 
            ||
| 327 | 44 | protected function substitutePageDocument(\Apache_Solr_Document $pageDocument)  | 
            |
| 356 | |||
| 357 | 44 | /**  | 
            |
| 358 | * Retrieves the indexConfigurationName from the related queueItem, or falls back to pages when no queue item set.  | 
            ||
| 359 | *  | 
            ||
| 360 | * @return string  | 
            ||
| 361 | */  | 
            ||
| 362 | protected function getIndexConfigurationNameForCurrentPage()  | 
            ||
| 366 | |||
| 367 | /**  | 
            ||
| 368 | 44 | * Allows third party extensions to provide additional documents which  | 
            |
| 369 | * should be indexed for the current page.  | 
            ||
| 370 | *  | 
            ||
| 371 | * @param \Apache_Solr_Document $pageDocument The main document representing this page.  | 
            ||
| 372 | * @param \Apache_Solr_Document[] $existingDocuments An array of documents already created for this page.  | 
            ||
| 373 | * @return array An array of additional \Apache_Solr_Document objects to index  | 
            ||
| 374 | */  | 
            ||
| 375 | protected function getAdditionalDocuments(\Apache_Solr_Document $pageDocument, array $existingDocuments)  | 
            ||
| 399 | |||
| 400 | /**  | 
            ||
| 401 | * Sends the given documents to the field processing service which takes  | 
            ||
| 402 | 44 | * care of manipulating fields as defined in the field's configuration.  | 
            |
| 403 | *  | 
            ||
| 404 | 44 | * @param array $documents An array of documents to manipulate  | 
            |
| 405 | 44 | */  | 
            |
| 406 | 44 | protected function processDocuments(array $documents)  | 
            |
| 414 | |||
| 415 | /**  | 
            ||
| 416 | * Adds the collected documents to the Solr index.  | 
            ||
| 417 | *  | 
            ||
| 418 | 44 | * @param array $documents An array of \Apache_Solr_Document objects.  | 
            |
| 419 | * @return bool TRUE if documents were added successfully, FALSE otherwise  | 
            ||
| 420 | 44 | */  | 
            |
| 421 | 44 | protected function addDocumentsToSolrIndex(array $documents)  | 
            |
| 467 | 38 | ||
| 468 | /**  | 
            ||
| 469 | * Gets the current page's URL.  | 
            ||
| 470 | 6 | *  | 
            |
| 471 | 6 | * @return string URL of the current page.  | 
            |
| 472 | 6 | */  | 
            |
| 473 | public function getPageUrl()  | 
            ||
| 477 | |||
| 478 | /**  | 
            ||
| 479 | 6 | * Sets the URL to use for the page document.  | 
            |
| 480 | 6 | *  | 
            |
| 481 | * @param string $url The page's URL.  | 
            ||
| 482 | */  | 
            ||
| 483 | 6 | public function setPageUrl($url)  | 
            |
| 487 | |||
| 488 | 6 | /**  | 
            |
| 489 | * Gets the page's access rootline.  | 
            ||
| 490 | *  | 
            ||
| 491 | 6 | * @return Rootline The page's access rootline  | 
            |
| 492 | */  | 
            ||
| 493 | public function getPageAccessRootline()  | 
            ||
| 497 | |||
| 498 | /**  | 
            ||
| 499 | 6 | * Sets the page's access rootline.  | 
            |
| 500 | *  | 
            ||
| 501 | 6 | * @param Rootline $accessRootline The page's access rootline  | 
            |
| 502 | */  | 
            ||
| 503 | public function setPageAccessRootline(Rootline $accessRootline)  | 
            ||
| 507 | |||
| 508 | /**  | 
            ||
| 509 | * Gets the documents that have been sent to Solr  | 
            ||
| 510 | *  | 
            ||
| 511 | * @return array An array of \Apache_Solr_Document objects  | 
            ||
| 512 | 44 | */  | 
            |
| 513 | public function getDocumentsSentToSolr()  | 
            ||
| 517 | }  | 
            ||
| 518 |