Complex classes like PluginBase 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 PluginBase, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
48 | abstract class PluginBase extends AbstractPlugin |
||
49 | { |
||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | public $prefixId = 'tx_solr'; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | public $extKey = 'solr'; |
||
59 | |||
60 | /** |
||
61 | * The plugin's query |
||
62 | * |
||
63 | * @deprecated use $this->searchResultSet->getUsedQuery() instead, will be removed in version 5.0 |
||
64 | * @var Query |
||
65 | */ |
||
66 | protected $query = null; |
||
67 | |||
68 | /** |
||
69 | * An instance of ApacheSolrForTypo3\Solr\Template |
||
70 | * |
||
71 | * @var Template |
||
72 | */ |
||
73 | protected $template; |
||
74 | |||
75 | /** |
||
76 | * An instance of ApacheSolrForTypo3\Solr\JavascriptManager |
||
77 | * |
||
78 | * @var JavascriptManager |
||
79 | */ |
||
80 | protected $javascriptManager; |
||
81 | |||
82 | /** |
||
83 | * An instance of the localization factory |
||
84 | * |
||
85 | * @var \TYPO3\CMS\Core\Localization\LocalizationFactory |
||
86 | */ |
||
87 | protected $languageFactory; |
||
88 | |||
89 | /** |
||
90 | * The user's raw query. |
||
91 | * |
||
92 | * Private to enforce API usage. |
||
93 | * |
||
94 | * @var string |
||
95 | */ |
||
96 | private $rawUserQuery; |
||
97 | |||
98 | // Main |
||
99 | |||
100 | /** |
||
101 | * @var TypoScriptConfiguration |
||
102 | */ |
||
103 | public $typoScriptConfiguration; |
||
104 | |||
105 | /** |
||
106 | * @var SearchResultSetService |
||
107 | */ |
||
108 | private $searchResultsSetService; |
||
109 | |||
110 | /** |
||
111 | * The main method of the plugin |
||
112 | * |
||
113 | * @param string $content The plugin content |
||
114 | * @param array $configuration The plugin configuration |
||
115 | * @return string The content that is displayed on the website |
||
116 | */ |
||
117 | 25 | public function main($content, $configuration) |
|
151 | |||
152 | /** |
||
153 | * Adds the possibility to use stdWrap on the plugins content instead of wrapInBaseClass. |
||
154 | * Defaults to wrapInBaseClass to ensure downward compatibility. |
||
155 | * |
||
156 | * @param string $content The plugin content |
||
157 | * @return string |
||
158 | */ |
||
159 | 25 | protected function baseWrap($content) |
|
169 | |||
170 | /** |
||
171 | * Implements the action logic. The result of this method is passed to the |
||
172 | * render method. |
||
173 | * |
||
174 | * @return string Action result |
||
175 | */ |
||
176 | abstract protected function performAction(); |
||
177 | |||
178 | // Initialization |
||
179 | |||
180 | /** |
||
181 | * Initializes the plugin - configuration, language, caching, search... |
||
182 | * |
||
183 | * @param array $configuration configuration array as provided by the TYPO3 core |
||
184 | */ |
||
185 | 25 | protected function initialize($configuration) |
|
206 | |||
207 | /** |
||
208 | * Overwrites pi_setPiVarDefaults to add stdWrap-functionality to _DEFAULT_PI_VARS |
||
209 | * |
||
210 | * @author Grigori Prokhorov <[email protected]> |
||
211 | * @author Ivan Kartolo <[email protected]> |
||
212 | * @return void |
||
213 | */ |
||
214 | 25 | public function pi_setPiVarDefaults() |
|
230 | |||
231 | /** |
||
232 | * Overwrites pi_loadLL() to handle custom location of language files. |
||
233 | * |
||
234 | * Loads local-language values by looking for a "locallang" file in the |
||
235 | * plugin class directory ($this->scriptRelPath) and if found includes it. |
||
236 | * Also locallang values set in the TypoScript property "_LOCAL_LANG" are |
||
237 | * merged onto the values found in the "locallang" file. |
||
238 | * Supported file extensions xlf, xml, php |
||
239 | * |
||
240 | * @param string $languageFilePath path to the plugin language file in format EXT:.... |
||
241 | * @return void |
||
242 | */ |
||
243 | 25 | public function pi_loadLL($languageFilePath = '') |
|
291 | |||
292 | /** |
||
293 | * Allows to override TypoScript settings with Flexform values. |
||
294 | * |
||
295 | */ |
||
296 | 3 | protected function overrideTyposcriptWithFlexformSettings() |
|
299 | |||
300 | /** |
||
301 | * Initializes the query from the GET query parameter. |
||
302 | * |
||
303 | */ |
||
304 | 25 | protected function initializeQuery() |
|
308 | |||
309 | /** |
||
310 | * Initializes the Solr connection and tests the connection through a ping. |
||
311 | * |
||
312 | */ |
||
313 | 25 | protected function initializeSearch() |
|
327 | |||
328 | /** |
||
329 | * @return SearchResultSetService |
||
330 | */ |
||
331 | 25 | public function getSearchResultSetService() |
|
335 | |||
336 | /** |
||
337 | * Initializes the template engine and returns the initialized instance. |
||
338 | * |
||
339 | * @return Template |
||
340 | * @throws \UnexpectedValueException if a view helper provider fails to implement interface ApacheSolrForTypo3\Solr\ViewHelper\ViewHelperProvider |
||
341 | */ |
||
342 | 25 | protected function initializeTemplateEngine() |
|
395 | |||
396 | /** |
||
397 | * Initializes the javascript manager. |
||
398 | * |
||
399 | */ |
||
400 | 25 | protected function initializeJavascriptManager() |
|
404 | |||
405 | /** |
||
406 | * Initializes the language factory; |
||
407 | */ |
||
408 | 25 | protected function initializeLanguageFactory() |
|
412 | |||
413 | /** |
||
414 | * This method is called after initializing in the initialize method. |
||
415 | * Overwrite this method to do your own initialization. |
||
416 | * |
||
417 | * @return void |
||
418 | */ |
||
419 | 3 | protected function postInitialize() |
|
422 | |||
423 | /** |
||
424 | * Overwrite this method to do own initialisations of the template. |
||
425 | * |
||
426 | * @param Template $template Template |
||
427 | * @return Template |
||
428 | */ |
||
429 | protected function postInitializeTemplateEngine(Template $template) |
||
433 | |||
434 | // Rendering |
||
435 | |||
436 | /** |
||
437 | * This method executes the requested commands and applies the changes to |
||
438 | * the template. |
||
439 | * |
||
440 | * @param $actionResult |
||
441 | * @return string Rendered plugin content |
||
442 | */ |
||
443 | abstract protected function render($actionResult); |
||
444 | |||
445 | /** |
||
446 | * Renders a solr error. |
||
447 | * |
||
448 | * @return string A representation of the error that should be understandable for the user. |
||
449 | */ |
||
450 | protected function renderError() |
||
456 | |||
457 | /** |
||
458 | * Renders a solr exception. |
||
459 | * |
||
460 | * @return string A representation of the exception that should be understandable for the user. |
||
461 | */ |
||
462 | protected function renderException() |
||
468 | |||
469 | /** |
||
470 | * Should be overwritten to do things before rendering. |
||
471 | * |
||
472 | */ |
||
473 | 2 | protected function preRender() |
|
476 | |||
477 | /** |
||
478 | * Overwrite this method to perform changes to the content after rendering. |
||
479 | * |
||
480 | * @param string $content The content rendered by the plugin so far |
||
481 | * @return string The content that should be presented on the website, might be different from the output rendered before |
||
482 | */ |
||
483 | 25 | protected function postRender($content) |
|
491 | |||
492 | // Helper methods |
||
493 | |||
494 | /** |
||
495 | * Determines the template file from the configuration. |
||
496 | * |
||
497 | * Overwrite this method to use a different template. |
||
498 | * |
||
499 | * @return string The template file name to be used for the plugin |
||
500 | */ |
||
501 | 25 | protected function getTemplateFile() |
|
505 | |||
506 | /** |
||
507 | * This method should be implemented to return the TSconfig key which |
||
508 | * contains the template name for this template. |
||
509 | * |
||
510 | * @see initializeTemplateEngine() |
||
511 | * @return string The TSconfig key containing the template name |
||
512 | */ |
||
513 | abstract protected function getTemplateFileKey(); |
||
514 | |||
515 | /** |
||
516 | * Gets the plugin's template instance. |
||
517 | * |
||
518 | * @return Template The plugin's template. |
||
519 | */ |
||
520 | 25 | public function getTemplate() |
|
524 | |||
525 | /** |
||
526 | * Gets the plugin's javascript manager. |
||
527 | * |
||
528 | * @return JavascriptManager The plugin's javascript manager. |
||
529 | */ |
||
530 | 25 | public function getJavascriptManager() |
|
534 | |||
535 | /** |
||
536 | * Should return the relevant subpart of the template. |
||
537 | * |
||
538 | * @see initializeTemplateEngine() |
||
539 | * @return string The subpart of the template to be used |
||
540 | */ |
||
541 | abstract protected function getSubpart(); |
||
542 | |||
543 | /** |
||
544 | * This method should return the plugin key. Reads some configuration |
||
545 | * options in initializeTemplateEngine() |
||
546 | * |
||
547 | * @see initializeTemplateEngine() |
||
548 | * @return string The plugin key |
||
549 | */ |
||
550 | abstract protected function getPluginKey(); |
||
551 | |||
552 | /** |
||
553 | * Gets the target page Id for links. Might have been set through either |
||
554 | * flexform or TypoScript. If none is set, TSFE->id is used. |
||
555 | * |
||
556 | * @return int The page Id to be used for links |
||
557 | */ |
||
558 | 18 | public function getLinkTargetPageId() |
|
562 | |||
563 | /** |
||
564 | * Gets the user's query term and cleans it so that it can be used in |
||
565 | * templates f.e. |
||
566 | * |
||
567 | * @return string The cleaned user query. |
||
568 | */ |
||
569 | 25 | public function getCleanUserQuery() |
|
583 | |||
584 | /** |
||
585 | * Gets the raw user query |
||
586 | * |
||
587 | * @return string Raw user query. |
||
588 | */ |
||
589 | 25 | public function getRawUserQuery() |
|
593 | |||
594 | /** |
||
595 | * @return string |
||
596 | */ |
||
597 | 25 | protected function getCurrentUrlWithQueryLinkBuilder() |
|
613 | } |
||
614 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.