Conditions | 13 |
Paths | 17 |
Total Lines | 62 |
Code Lines | 39 |
Lines | 3 |
Ratio | 4.84 % |
Changes | 4 | ||
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 |
||
76 | public function load($token) { |
||
77 | try { |
||
78 | $share = $this->shareManager->getShareByToken($token); |
||
79 | } catch (ShareNotFound $e) { |
||
|
|||
80 | return new DataResponse(['message' => $this->l->t('Share not found'), Http::STATUS_NOT_FOUND]); |
||
81 | } |
||
82 | |||
83 | if ($share->getPassword() !== null && |
||
84 | (!$this->session->exists('public_link_authenticated') |
||
85 | || $this->session->get('public_link_authenticated') !== (string)$share->getId())) { |
||
86 | return new DataResponse(['message' => $this->l->t('You are not authorized to open this share'), Http::STATUS_BAD_REQUEST]); |
||
87 | } |
||
88 | |||
89 | try { |
||
90 | $node = $share->getNode(); |
||
91 | } catch (NotFoundException $e) { |
||
92 | return new DataResponse(['message' => $this->l->t('Share not found'), Http::STATUS_NOT_FOUND]); |
||
93 | } |
||
94 | |||
95 | if ($node instanceof Folder) { |
||
96 | return new DataResponse(['message' => $this->l->t('You can not open a folder')], Http::STATUS_BAD_REQUEST); |
||
97 | } |
||
98 | |||
99 | $range = $this->request->getHeader('Range'); |
||
100 | if ($range !== '') { |
||
101 | $matches = []; |
||
102 | View Code Duplication | if (preg_match('/bytes=0-(\d+)$/', $range, $matches) === 0) { |
|
103 | return new DataResponse(['message' => $this->l->t('Invalid range request')], Http::STATUS_REQUEST_RANGE_NOT_SATISFIABLE); |
||
104 | } |
||
105 | $range = (int)$matches[1]; |
||
106 | } else { |
||
107 | $range = -1; |
||
108 | } |
||
109 | |||
110 | // default of 4MB |
||
111 | $maxSize = 4194304; |
||
112 | if ($node->getSize() > $maxSize) { |
||
113 | return new DataResponse(['message' => $this->l->t('This file is too big to be opened. Please download the file instead.')], Http::STATUS_BAD_REQUEST); |
||
114 | } |
||
115 | |||
116 | $fileContents = $node->getContent(); |
||
117 | if ($fileContents !== false) { |
||
118 | $encoding = mb_detect_encoding($fileContents . 'a', 'UTF-8, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII', true); |
||
119 | if ($encoding === '') { |
||
120 | // set default encoding if it couldn't be detected |
||
121 | $encoding = 'ISO-8859-15'; |
||
122 | } |
||
123 | $fileContents = iconv($encoding, 'UTF-8', $fileContents); |
||
124 | |||
125 | if ($range !== -1) { |
||
126 | $fileContents = mb_substr($fileContents, 0, $range); |
||
127 | } |
||
128 | |||
129 | return new Http\DataDisplayResponse( |
||
130 | $fileContents, |
||
131 | Http::STATUS_OK, |
||
132 | ['Content-Type' => 'text/plain; charset="utf-8"'] |
||
133 | ); |
||
134 | } |
||
135 | |||
136 | return new DataResponse(['message' => $this->l->t('Cannot read the file.')], Http::STATUS_BAD_REQUEST); |
||
137 | } |
||
138 | } |
||
139 |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.