We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 16 |
| Paths | 1601 |
| Total Lines | 103 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 99 | public function main($content, $conf) |
||
| 100 | { |
||
| 101 | $this->init($conf); |
||
| 102 | // Turn cache on. |
||
| 103 | $this->setCache(true); |
||
| 104 | // Load current document. |
||
| 105 | $this->loadDocument(); |
||
| 106 | if ($this->doc === null) { |
||
| 107 | // Quit without doing anything if required variables are not set. |
||
| 108 | return $content; |
||
| 109 | } else { |
||
| 110 | // Set default values if not set. |
||
| 111 | if ($this->doc->numPages > 0) { |
||
| 112 | if (!empty($this->piVars['logicalPage'])) { |
||
| 113 | $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); |
||
|
|
|||
| 114 | // The logical page parameter should not appear |
||
| 115 | unset($this->piVars['logicalPage']); |
||
| 116 | } |
||
| 117 | // Set default values if not set. |
||
| 118 | // $this->piVars['page'] may be integer or string (physical structure @ID) |
||
| 119 | if ( |
||
| 120 | (int) $this->piVars['page'] > 0 |
||
| 121 | || empty($this->piVars['page']) |
||
| 122 | ) { |
||
| 123 | $this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1); |
||
| 124 | } else { |
||
| 125 | $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure); |
||
| 126 | } |
||
| 127 | $this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0); |
||
| 128 | } else { |
||
| 129 | $this->piVars['page'] = 0; |
||
| 130 | $this->piVars['double'] = 0; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | // Load template file. |
||
| 134 | $this->getTemplate(); |
||
| 135 | // Steps for X pages backward / forward. Double page view uses double steps. |
||
| 136 | $pageSteps = $this->conf['pageStep'] * ($this->piVars['double'] + 1); |
||
| 137 | // Link to first page. |
||
| 138 | if ($this->piVars['page'] > 1) { |
||
| 139 | $markerArray['###FIRST###'] = $this->makeLink($this->pi_getLL('firstPage', '', true), ['page' => 1]); |
||
| 140 | } else { |
||
| 141 | $markerArray['###FIRST###'] = '<span title="' . $this->pi_getLL('firstPage', '', true) . '">' . $this->pi_getLL('firstPage', '', true) . '</span>'; |
||
| 142 | } |
||
| 143 | // Link back X pages. |
||
| 144 | if ($this->piVars['page'] > $pageSteps) { |
||
| 145 | $markerArray['###BACK###'] = $this->makeLink(sprintf($this->pi_getLL('backXPages', '', true), $pageSteps), ['page' => $this->piVars['page'] - $pageSteps]); |
||
| 146 | } else { |
||
| 147 | $markerArray['###BACK###'] = '<span title="' . sprintf($this->pi_getLL('backXPages', '', true), $pageSteps) . '">' . sprintf($this->pi_getLL('backXPages', '', true), $pageSteps) . '</span>'; |
||
| 148 | } |
||
| 149 | // Link to previous page. |
||
| 150 | if ($this->piVars['page'] > (1 + $this->piVars['double'])) { |
||
| 151 | $markerArray['###PREVIOUS###'] = $this->makeLink($this->pi_getLL('prevPage', '', true), ['page' => $this->piVars['page'] - (1 + $this->piVars['double'])]); |
||
| 152 | } else { |
||
| 153 | $markerArray['###PREVIOUS###'] = '<span title="' . $this->pi_getLL('prevPage', '', true) . '">' . $this->pi_getLL('prevPage', '', true) . '</span>'; |
||
| 154 | } |
||
| 155 | // Link to next page. |
||
| 156 | if ($this->piVars['page'] < ($this->doc->numPages - $this->piVars['double'])) { |
||
| 157 | $markerArray['###NEXT###'] = $this->makeLink($this->pi_getLL('nextPage', '', true), ['page' => $this->piVars['page'] + (1 + $this->piVars['double'])]); |
||
| 158 | } else { |
||
| 159 | $markerArray['###NEXT###'] = '<span title="' . $this->pi_getLL('nextPage', '', true) . '">' . $this->pi_getLL('nextPage', '', true) . '</span>'; |
||
| 160 | } |
||
| 161 | // Link forward X pages. |
||
| 162 | if ($this->piVars['page'] <= ($this->doc->numPages - $pageSteps)) { |
||
| 163 | $markerArray['###FORWARD###'] = $this->makeLink(sprintf($this->pi_getLL('forwardXPages', '', true), $pageSteps), ['page' => $this->piVars['page'] + $pageSteps]); |
||
| 164 | } else { |
||
| 165 | $markerArray['###FORWARD###'] = '<span title="' . sprintf($this->pi_getLL('forwardXPages', '', true), $pageSteps) . '">' . sprintf($this->pi_getLL('forwardXPages', '', true), $pageSteps) . '</span>'; |
||
| 166 | } |
||
| 167 | // Link to last page. |
||
| 168 | if ($this->piVars['page'] < $this->doc->numPages) { |
||
| 169 | $markerArray['###LAST###'] = $this->makeLink($this->pi_getLL('lastPage', '', true), ['page' => $this->doc->numPages]); |
||
| 170 | } else { |
||
| 171 | $markerArray['###LAST###'] = '<span title="' . $this->pi_getLL('lastPage', '', true) . '">' . $this->pi_getLL('lastPage', '', true) . '</span>'; |
||
| 172 | } |
||
| 173 | // Add double page switcher. |
||
| 174 | if ($this->doc->numPages > 0) { |
||
| 175 | if (!$this->piVars['double']) { |
||
| 176 | $markerArray['###DOUBLEPAGE###'] = $this->makeLink($this->pi_getLL('doublePageOn', '', true), ['double' => 1], 'class="tx-dlf-navigation-doubleOn" title="' . $this->pi_getLL('doublePageOn', '', true) . '"'); |
||
| 177 | } else { |
||
| 178 | $markerArray['###DOUBLEPAGE###'] = $this->makeLink($this->pi_getLL('doublePageOff', '', true), ['double' => 0], 'class="tx-dlf-navigation-doubleOff" title="' . $this->pi_getLL('doublePageOff', '', true) . '"'); |
||
| 179 | } |
||
| 180 | if ($this->piVars['double'] && $this->piVars['page'] < $this->doc->numPages) { |
||
| 181 | $markerArray['###DOUBLEPAGE+1###'] = $this->makeLink($this->pi_getLL('doublePage+1', '', true), ['page' => $this->piVars['page'] + 1], 'title="' . $this->pi_getLL('doublePage+1', '', true) . '"'); |
||
| 182 | } else { |
||
| 183 | $markerArray['###DOUBLEPAGE+1###'] = '<span title="' . $this->pi_getLL('doublePage+1', '', true) . '">' . $this->pi_getLL('doublePage+1', '', true) . '</span>'; |
||
| 184 | } |
||
| 185 | } else { |
||
| 186 | $markerArray['###DOUBLEPAGE###'] = '<span title="' . $this->pi_getLL('doublePageOn', '', true) . '">' . $this->pi_getLL('doublePageOn', '', true) . '</span>'; |
||
| 187 | $markerArray['###DOUBLEPAGE+1###'] = '<span title="' . $this->pi_getLL('doublePage+1', '', true) . '">' . $this->pi_getLL('doublePage+1', '', true) . '</span>'; |
||
| 188 | } |
||
| 189 | // Add page selector. |
||
| 190 | $markerArray['###PAGESELECT###'] = $this->getPageSelector(); |
||
| 191 | // Add link to listview if applicable. |
||
| 192 | $markerArray['###LINKLISTVIEW###'] = $this->getLinkToListview(); |
||
| 193 | // Fill some language labels if available. |
||
| 194 | $markerArray['###ZOOM_IN###'] = $this->pi_getLL('zoom-in', '', true); |
||
| 195 | $markerArray['###ZOOM_OUT###'] = $this->pi_getLL('zoom-out', '', true); |
||
| 196 | $markerArray['###ZOOM_FULLSCREEN###'] = $this->pi_getLL('zoom-fullscreen', '', true); |
||
| 197 | $markerArray['###ROTATE_LEFT###'] = $this->pi_getLL('rotate-left', '', true); |
||
| 198 | $markerArray['###ROTATE_RIGHT###'] = $this->pi_getLL('rotate-right', '', true); |
||
| 199 | $markerArray['###ROTATE_RESET###'] = $this->pi_getLL('rotate-reset', '', true); |
||
| 200 | $content .= $this->templateService->substituteMarkerArray($this->template, $markerArray); |
||
| 201 | return $this->pi_wrapInBaseClass($content); |
||
| 202 | } |
||
| 236 |