Conditions | 10 |
Paths | 31 |
Total Lines | 54 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 | $pageOptions = []; |
||
99 | for ($i = 1; $i <= $this->document->getDoc()->numPages; $i++) { |
||
100 | $pageOptions[$i] = '[' . $i . ']' . ($this->document->getDoc()->physicalStructureInfo[$this->document->getDoc()->physicalStructure[$i]]['orderlabel'] ? ' - ' . htmlspecialchars($this->document->getDoc()->physicalStructureInfo[$this->document->getDoc()->physicalStructure[$i]]['orderlabel']) : ''); |
||
101 | } |
||
102 | $this->view->assign('pageOptions', $pageOptions); |
||
103 | |||
104 | // prepare feature array for fluid |
||
105 | $features = []; |
||
106 | foreach (explode(',', $this->settings['features']) as $feature) { |
||
107 | $features[$feature] = true; |
||
108 | } |
||
109 | $this->view->assign('features', $features); |
||
110 | } |
||
112 |