| Conditions | 11 |
| Paths | 105 |
| Total Lines | 34 |
| Code Lines | 21 |
| 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 |
||
| 26 | public function getUploadSize($path) { |
||
| 27 | $uploadSize = null; |
||
| 28 | |||
| 29 | try { |
||
| 30 | $requestMethod = $this->request->getMethod(); |
||
| 31 | $isRemoteScript = $this->isScriptName('remote.php'); |
||
| 32 | // Are we uploading anything? |
||
| 33 | if (in_array($requestMethod, ['MOVE', 'PUT']) && $isRemoteScript) { |
||
| 34 | $pathInfo = $this->request->getPathInfo(); |
||
| 35 | |||
| 36 | // Chunks are not scanned |
||
| 37 | $isChunk = \OC_FileChunking::isWebdavChunk() |
||
| 38 | || ($requestMethod === 'PUT' && strpos($path, 'uploads/') === 0); |
||
| 39 | if ($isChunk) { |
||
| 40 | return null; |
||
| 41 | } |
||
| 42 | |||
| 43 | $isDavPathV1 = $pathInfo === '/webdav' || strpos($pathInfo, '/webdav/') === 0; |
||
|
|
|||
| 44 | $isDavPathV2 = $pathInfo === '/dav/files' |
||
| 45 | || strpos($pathInfo, '/dav/files/') === 0 |
||
| 46 | || strpos($pathInfo, '/dav/uploads/') === 0; |
||
| 47 | |||
| 48 | if ($requestMethod === 'PUT') { |
||
| 49 | $uploadSize = (int)$this->request->getHeader('CONTENT_LENGTH'); |
||
| 50 | } else { |
||
| 51 | $uploadSize = (int)$this->request->getHeader('OC_TOTAL_LENGTH'); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | } catch (\Exception $e) { |
||
| 55 | // Happens in CLI mode |
||
| 56 | } |
||
| 57 | |||
| 58 | return $uploadSize; |
||
| 59 | } |
||
| 60 | |||
| 71 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.