| Conditions | 13 |
| Paths | 50 |
| Total Lines | 77 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 43 | public function main($content, $conf) |
||
| 44 | { |
||
| 45 | |||
| 46 | $this->init($conf); |
||
| 47 | |||
| 48 | // Merge configuration with conf array of toolbox. |
||
| 49 | if (!empty($this->cObj->data['conf'])) { |
||
| 50 | $this->conf = Helper::mergeRecursiveWithOverrule($this->cObj->data['conf'], $this->conf); |
||
|
|
|||
| 51 | } |
||
| 52 | |||
| 53 | // Load current document. |
||
| 54 | $this->loadDocument(); |
||
| 55 | if ( |
||
| 56 | $this->doc === null |
||
| 57 | || $this->doc->numPages < 1 |
||
| 58 | || empty($this->conf['fileGrpFulltext']) |
||
| 59 | || empty($this->conf['solrcore']) |
||
| 60 | ) { |
||
| 61 | // Quit without doing anything if required variables are not set. |
||
| 62 | return $content; |
||
| 63 | } else { |
||
| 64 | if (!empty($this->piVars['logicalPage'])) { |
||
| 65 | $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); |
||
| 66 | // The logical page parameter should not appear again |
||
| 67 | unset($this->piVars['logicalPage']); |
||
| 68 | } |
||
| 69 | // Set default values if not set. |
||
| 70 | // $this->piVars['page'] may be integer or string (physical structure @ID) |
||
| 71 | if ( |
||
| 72 | (int) $this->piVars['page'] > 0 |
||
| 73 | || empty($this->piVars['page']) |
||
| 74 | ) { |
||
| 75 | $this->piVars['page'] = MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1); |
||
| 76 | } else { |
||
| 77 | $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 81 | // Quit if no fulltext file is present |
||
| 82 | $fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->conf['fileGrpFulltext']); |
||
| 83 | while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) { |
||
| 84 | if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$fileGrpFulltext])) { |
||
| 85 | $fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$fileGrpFulltext]; |
||
| 86 | break; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | if (empty($fullTextFile)) { |
||
| 90 | return $content; |
||
| 91 | } |
||
| 92 | |||
| 93 | // Load template file. |
||
| 94 | $this->getTemplate(); |
||
| 95 | |||
| 96 | // Fill markers. |
||
| 97 | $markerArray = [ |
||
| 98 | '###ACTION_URL###' => $this->getActionUrl(), |
||
| 99 | '###LABEL_QUERY###' => htmlspecialchars($this->pi_getLL('label.query')), |
||
| 100 | '###LABEL_DELETE_SEARCH###' => htmlspecialchars($this->pi_getLL('label.delete_search')), |
||
| 101 | '###LABEL_LOADING###' => htmlspecialchars($this->pi_getLL('label.loading')), |
||
| 102 | '###LABEL_SUBMIT###' => htmlspecialchars($this->pi_getLL('label.submit')), |
||
| 103 | '###LABEL_SEARCH_IN_DOCUMENT###' => htmlspecialchars($this->pi_getLL('label.searchInDocument')), |
||
| 104 | '###LABEL_NEXT###' => htmlspecialchars($this->pi_getLL('label.next')), |
||
| 105 | '###LABEL_PREVIOUS###' => htmlspecialchars($this->pi_getLL('label.previous')), |
||
| 106 | '###LABEL_PAGE###' => htmlspecialchars($this->pi_getLL('label.logicalPage')), |
||
| 107 | '###LABEL_NORESULT###' => htmlspecialchars($this->pi_getLL('label.noresult')), |
||
| 108 | '###LABEL_QUERY_URL###' => $this->conf['queryInputName'], |
||
| 109 | '###LABEL_START###' => $this->conf['startInputName'], |
||
| 110 | '###LABEL_ID###' => $this->conf['idInputName'], |
||
| 111 | '###LABEL_PAGE_URL###' => $this->conf['pageInputName'], |
||
| 112 | '###LABEL_HIGHLIGHT_WORD###' => $this->conf['highlightWordInputName'], |
||
| 113 | '###LABEL_ENCRYPTED###' => $this->conf['encryptedInputName'], |
||
| 114 | '###CURRENT_DOCUMENT###' => $this->getCurrentDocumentId(), |
||
| 115 | '###SOLR_ENCRYPTED###' => $this->getEncryptedCoreName() ? : '' |
||
| 116 | ]; |
||
| 117 | |||
| 118 | $content .= $this->templateService->substituteMarkerArray($this->template, $markerArray); |
||
| 119 | return $this->pi_wrapInBaseClass($content); |
||
| 120 | } |
||
| 188 |