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