| Conditions | 10 |
| Paths | 28 |
| Total Lines | 41 |
| Code Lines | 22 |
| 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 |
||
| 50 | public function search($query, int $limit = null, int $offset = null) { |
||
| 51 | if ($offset === null) { |
||
| 52 | $offset = 0; |
||
| 53 | } |
||
| 54 | \OC_Util::setupFS(); |
||
| 55 | $files = Filesystem::search($query); |
||
| 56 | $results = []; |
||
| 57 | if ($limit !== null) { |
||
| 58 | $files = array_slice($files, $offset, $offset + $limit); |
||
| 59 | } |
||
| 60 | // edit results |
||
| 61 | foreach ($files as $fileData) { |
||
| 62 | // skip versions |
||
| 63 | if (strpos($fileData['path'], '_versions') === 0) { |
||
| 64 | continue; |
||
| 65 | } |
||
| 66 | // skip top-level folder |
||
| 67 | if ($fileData['name'] === 'files' && $fileData['parent'] === -1) { |
||
| 68 | continue; |
||
| 69 | } |
||
| 70 | // create audio result |
||
| 71 | if ($fileData['mimepart'] === 'audio') { |
||
| 72 | $result = new \OC\Search\Result\Audio($fileData); |
||
| 73 | } |
||
| 74 | // create image result |
||
| 75 | elseif ($fileData['mimepart'] === 'image') { |
||
| 76 | $result = new \OC\Search\Result\Image($fileData); |
||
| 77 | } |
||
| 78 | // create folder result |
||
| 79 | elseif ($fileData['mimetype'] === 'httpd/unix-directory') { |
||
| 80 | $result = new \OC\Search\Result\Folder($fileData); |
||
| 81 | } |
||
| 82 | // or create file result |
||
| 83 | else { |
||
| 84 | $result = new \OC\Search\Result\File($fileData); |
||
| 85 | } |
||
| 86 | // add to results |
||
| 87 | $results[] = $result; |
||
| 88 | } |
||
| 89 | // return |
||
| 90 | return $results; |
||
| 91 | } |
||
| 101 |