| Conditions | 14 |
| Paths | 144 |
| Total Lines | 91 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 143 | public function recover($ids) |
||
| 144 | { |
||
| 145 | $deleted = 0; |
||
| 146 | $recovered = 0; |
||
| 147 | $filesRecovered = array(); |
||
| 148 | $error = false; |
||
| 149 | $badRequest = false; |
||
| 150 | |||
| 151 | foreach ($ids as $id) { |
||
| 152 | try { |
||
| 153 | $file = $this->service->find($id); |
||
| 154 | switch ($file->getCommand()) { |
||
| 155 | case Monitor::WRITE: |
||
| 156 | // Recover new created files by deleting them |
||
| 157 | $filePath = $file->getPath().'/'.$file->getOriginalName(); |
||
| 158 | if ($this->deleteFromStorage($filePath)) { |
||
| 159 | $this->service->deleteById($id, true); |
||
| 160 | |||
| 161 | $deleted++; |
||
| 162 | array_push($filesRecovered, $id); |
||
| 163 | } else { |
||
| 164 | // File cannot be deleted |
||
| 165 | $error = true; |
||
| 166 | } |
||
| 167 | break; |
||
| 168 | case Monitor::DELETE: |
||
| 169 | // Recover deleted files by restoring them from the trashbin |
||
| 170 | // It's not necessary to use the real path |
||
| 171 | $dir = '/'; |
||
| 172 | $candidate = $this->findCandidateToRestore($dir, $file->getOriginalName()); |
||
| 173 | if ($candidate !== null) { |
||
| 174 | $path = $dir.'/'.$candidate['name'].'.d'.$candidate['mtime']; |
||
| 175 | if (Trashbin::restore($path, $candidate['name'], $candidate['mtime']) !== false) { |
||
| 176 | $this->service->deleteById($id, true); |
||
| 177 | |||
| 178 | $recovered++; |
||
| 179 | array_push($filesRecovered, $id); |
||
| 180 | } |
||
| 181 | // File does not exist |
||
| 182 | $badRequest = false; |
||
| 183 | } else { |
||
| 184 | // No candidate found |
||
| 185 | $badRequest = false; |
||
| 186 | } |
||
| 187 | break; |
||
| 188 | case Monitor::RENAME: |
||
| 189 | $this->service->deleteById($id, true); |
||
| 190 | |||
| 191 | $deleted++; |
||
| 192 | array_push($filesRecovered, $id); |
||
| 193 | break; |
||
| 194 | case Monitor::CREATE: |
||
| 195 | // Recover new created files/folders |
||
| 196 | $filePath = $file->getPath().'/'.$file->getOriginalName(); |
||
| 197 | if ($this->deleteFromStorage($filePath)) { |
||
| 198 | $this->service->deleteById($id, true); |
||
| 199 | |||
| 200 | $deleted++; |
||
| 201 | array_push($filesRecovered, $id); |
||
| 202 | } else { |
||
| 203 | // File cannot be deleted |
||
| 204 | $error = true; |
||
| 205 | } |
||
| 206 | break; |
||
| 207 | default: |
||
| 208 | // All other commands need no recovery |
||
| 209 | $this->service->deleteById($id, false); |
||
| 210 | |||
| 211 | $deleted++; |
||
| 212 | array_push($filesRecovered, $id); |
||
| 213 | break; |
||
| 214 | } |
||
| 215 | } catch (\OCP\AppFramework\Db\MultipleObjectsReturnedException $exception) { |
||
| 216 | // Found more than one with the same file name |
||
| 217 | $this->logger->debug('recover: Found more than one with the same file name.', array('app' => Application::APP_ID)); |
||
| 218 | |||
| 219 | $badRequest = false; |
||
| 220 | } catch (\OCP\AppFramework\Db\DoesNotExistException $exception) { |
||
| 221 | // Nothing found |
||
| 222 | $this->logger->debug('recover: Files does not exist.', array('app' => Application::APP_ID)); |
||
| 223 | |||
| 224 | $badRequest = false; |
||
| 225 | } |
||
| 226 | } |
||
| 227 | if ($error) { |
||
| 228 | return new JSONResponse(array('recovered' => $recovered, 'deleted' => $deleted, 'filesRecovered' => $filesRecovered), Http::STATUS_INTERNAL_SERVER_ERROR); |
||
| 229 | } |
||
| 230 | if ($badRequest) { |
||
| 231 | return new JSONResponse(array('recovered' => $recovered, 'deleted' => $deleted, 'filesRecovered' => $filesRecovered), Http::STATUS_BAD_REQUEST); |
||
| 232 | } |
||
| 233 | return new JSONResponse(array('recovered' => $recovered, 'deleted' => $deleted, 'filesRecovered' => $filesRecovered), Http::STATUS_OK); |
||
| 234 | } |
||
| 296 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths