Conditions | 10 |
Paths | 38 |
Total Lines | 32 |
Code Lines | 18 |
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 |
||
25 | public function getUploadSize() { |
||
26 | // Chunks are not scanned anyway. Skip chunks dav v1 due to performance |
||
27 | if (\OC_FileChunking::isWebdavChunk()) { |
||
28 | return null; |
||
29 | } |
||
30 | |||
31 | try { |
||
32 | $pathInfo = $this->request->getPathInfo(); |
||
33 | } catch (\Exception $e) { |
||
34 | // CLI? |
||
35 | return null; |
||
36 | } |
||
37 | |||
38 | $requestMethod = $this->request->getMethod(); |
||
39 | |||
40 | $isRemoteScript = $this->isScriptName('remote.php'); |
||
41 | $isDavPathV1 = $pathInfo === '/webdav' || strpos($pathInfo, '/webdav/') === 0; |
||
42 | $isDavPathV2 = $pathInfo === '/dav/files' |
||
43 | || strpos($pathInfo, '/dav/files/') === 0 |
||
44 | || strpos($pathInfo, '/dav/uploads/') === 0 |
||
45 | ; |
||
46 | $isDavRequest = $isRemoteScript && ($isDavPathV1 || $isDavPathV2); |
||
47 | |||
48 | // No upload in progress |
||
49 | if (!$isDavRequest || !in_array($requestMethod, ['MOVE', 'PUT'])){ |
||
50 | return null; |
||
51 | } |
||
52 | |||
53 | $uploadSize = (int) $this->request->getHeader('CONTENT_LENGTH'); |
||
54 | |||
55 | return $uploadSize; |
||
56 | } |
||
57 | |||
67 | } |