| Conditions | 12 |
| Paths | 151 |
| Total Lines | 71 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 56 | public function mainAction() |
||
| 57 | { |
||
| 58 | // Load current document. |
||
| 59 | $this->loadDocument($this->requestData); |
||
| 60 | if ($this->isDocMissing()) { |
||
| 61 | // Quit without doing anything if required variables are not set. |
||
| 62 | return ''; |
||
|
|
|||
| 63 | } else { |
||
| 64 | // Set default values if not set. |
||
| 65 | if ($this->document->getDoc()->numPages > 0) { |
||
| 66 | if (!empty($this->requestData['logicalPage'])) { |
||
| 67 | $this->requestData['page'] = $this->document->getDoc()->getPhysicalPage($this->requestData['logicalPage']); |
||
| 68 | // The logical page parameter should not appear |
||
| 69 | unset($this->requestData['logicalPage']); |
||
| 70 | } |
||
| 71 | // Set default values if not set. |
||
| 72 | // $this->requestData['page'] may be integer or string (physical structure @ID) |
||
| 73 | if ( |
||
| 74 | (int) $this->requestData['page'] > 0 |
||
| 75 | || empty($this->requestData['page']) |
||
| 76 | ) { |
||
| 77 | $this->requestData['page'] = MathUtility::forceIntegerInRange((int) $this->requestData['page'], 1, $this->document->getDoc()->numPages, 1); |
||
| 78 | } else { |
||
| 79 | $this->requestData['page'] = array_search($this->requestData['page'], $this->document->getDoc()->physicalStructure); |
||
| 80 | } |
||
| 81 | $this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'], 0, 1, 0); |
||
| 82 | } else { |
||
| 83 | $this->requestData['page'] = 0; |
||
| 84 | $this->requestData['double'] = 0; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | // Steps for X pages backward / forward. Double page view uses double steps. |
||
| 89 | $pageSteps = $this->settings['pageStep'] * ($this->requestData['double'] + 1); |
||
| 90 | |||
| 91 | $this->view->assign('pageSteps', $pageSteps); |
||
| 92 | $this->view->assign('numPages', $this->document->getDoc()->numPages); |
||
| 93 | $this->view->assign('viewData', $this->viewData); |
||
| 94 | |||
| 95 | if ($GLOBALS['TSFE']->fe_user->getKey('ses', 'search')) { |
||
| 96 | $lastSearchArguments = []; |
||
| 97 | $searchSessionParameters = $GLOBALS['TSFE']->fe_user->getKey('ses', 'search'); |
||
| 98 | $widgetPage = $GLOBALS['TSFE']->fe_user->getKey('ses', 'widgetPage'); |
||
| 99 | |||
| 100 | if ($searchSessionParameters) { |
||
| 101 | $lastSearchArguments = [ |
||
| 102 | 'tx_dlf_listview' => [ |
||
| 103 | 'searchParameter' => $searchSessionParameters |
||
| 104 | ] |
||
| 105 | ]; |
||
| 106 | } |
||
| 107 | if ($widgetPage) { |
||
| 108 | $lastSearchArguments['tx_dlf_listview']['@widget_0'] = $widgetPage; |
||
| 109 | } |
||
| 110 | |||
| 111 | // save last search parameter to generate a link back to the search list |
||
| 112 | $this->view->assign('lastSearchParams', $lastSearchArguments); |
||
| 113 | } |
||
| 114 | |||
| 115 | $pageOptions = []; |
||
| 116 | for ($i = 1; $i <= $this->document->getDoc()->numPages; $i++) { |
||
| 117 | $pageOptions[$i] = '[' . $i . ']' . ($this->document->getDoc()->physicalStructureInfo[$this->document->getDoc()->physicalStructure[$i]]['orderlabel'] ? ' - ' . htmlspecialchars($this->document->getDoc()->physicalStructureInfo[$this->document->getDoc()->physicalStructure[$i]]['orderlabel']) : ''); |
||
| 118 | } |
||
| 119 | $this->view->assign('pageOptions', $pageOptions); |
||
| 120 | |||
| 121 | // prepare feature array for fluid |
||
| 122 | $features = []; |
||
| 123 | foreach (explode(',', $this->settings['features']) as $feature) { |
||
| 124 | $features[$feature] = true; |
||
| 125 | } |
||
| 126 | $this->view->assign('features', $features); |
||
| 127 | } |
||
| 129 |