We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 9 |
Paths | 17 |
Total Lines | 77 |
Code Lines | 46 |
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 |
||
37 | public function mainAction() |
||
38 | { |
||
39 | // Load current document. |
||
40 | $this->loadDocument($this->requestData); |
||
41 | if ( |
||
42 | $this->document === null |
||
43 | || $this->document->getDoc() === null |
||
44 | || $this->document->getDoc()->numPages < 1 |
||
45 | ) { |
||
46 | // Quit without doing anything if required variables are not set. |
||
47 | return; |
||
48 | } else { |
||
49 | if (!empty($this->requestData['logicalPage'])) { |
||
50 | $this->requestData['page'] = $this->document->getDoc()->getPhysicalPage($this->requestData['logicalPage']); |
||
51 | // The logical page parameter should not appear again |
||
52 | unset($this->requestData['logicalPage']); |
||
53 | } |
||
54 | // Set default values if not set. |
||
55 | // $this->requestData['page'] may be integer or string (physical structure @ID) |
||
56 | if ((int) $this->requestData['page'] > 0 || empty($this->requestData['page'])) { |
||
57 | $this->requestData['page'] = MathUtility::forceIntegerInRange((int) $this->requestData['page'], 1, $this->document->getDoc()->numPages, 1); |
||
58 | } else { |
||
59 | $this->requestData['page'] = array_search($this->requestData['page'], $this->document->getDoc()->physicalStructure); |
||
60 | } |
||
61 | $this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'], 0, 1, 0); |
||
62 | } |
||
63 | |||
64 | $doc = $this->document->getDoc(); |
||
|
|||
65 | |||
66 | if (!empty($this->settings['targetPidMetadata'])) { |
||
67 | $metadataUrl = $this->uriBuilder |
||
68 | ->reset() |
||
69 | ->setTargetPageUid((int) $this->settings['targetPidMetadata']) |
||
70 | ->setCreateAbsoluteUri(true) |
||
71 | ->setArguments([ |
||
72 | 'tx_dlf' => [ |
||
73 | 'id' => $this->requestData['id'], |
||
74 | ], |
||
75 | ]) |
||
76 | ->build(); |
||
77 | } |
||
78 | |||
79 | $imageFileGroups = array_reverse(GeneralUtility::trimExplode(',', $this->extConf['fileGrpImages'])); |
||
80 | $fulltextFileGroups = GeneralUtility::trimExplode(',', $this->extConf['fileGrpFulltext']); |
||
81 | $config = [ |
||
82 | 'forceAbsoluteUrl' => !empty($this->settings['forceAbsoluteUrl']), |
||
83 | 'proxyFileGroups' => !empty($this->settings['useInternalProxy']) |
||
84 | ? array_merge($imageFileGroups, $fulltextFileGroups) |
||
85 | : [], |
||
86 | ]; |
||
87 | $tx_dlf_loaded = [ |
||
88 | 'state' => [ |
||
89 | 'documentId' => $this->requestData['id'], |
||
90 | 'page' => $this->requestData['page'], |
||
91 | 'simultaneousPages' => (int) $this->requestData['double'] + 1, |
||
92 | ], |
||
93 | 'urlTemplate' => $this->getUrlTemplate(), |
||
94 | 'metadataUrl' => $metadataUrl, |
||
95 | 'fileGroups' => [ |
||
96 | 'images' => $imageFileGroups, |
||
97 | 'fulltext' => $fulltextFileGroups, |
||
98 | 'download' => GeneralUtility::trimExplode(',', $this->extConf['fileGrpDownload']), |
||
99 | ], |
||
100 | 'document' => $this->document->getDoc()->toArray($this->uriBuilder, $config), |
||
101 | ]; |
||
102 | |||
103 | $docConfiguration = ' |
||
104 | window.addEventListener("DOMContentLoaded", function() { |
||
105 | const tx_dlf_loaded = ' . json_encode($tx_dlf_loaded) . '; |
||
106 | window.dispatchEvent(new CustomEvent("tx-dlf-documentLoaded", { |
||
107 | detail: { |
||
108 | docController: new dlfController(tx_dlf_loaded) |
||
109 | } |
||
110 | })); |
||
111 | });'; |
||
112 | |||
113 | $this->view->assign('docConfiguration', $docConfiguration); |
||
114 | } |
||
190 |