| Conditions | 7 |
| Paths | 5 |
| Total Lines | 56 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 2 | 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 |
||
| 59 | public function fopen($path, $mode){ |
||
| 60 | $stream = $this->storage->fopen($path, $mode); |
||
| 61 | if (is_resource($stream) && $this->isWritingMode($mode)) { |
||
| 62 | try { |
||
| 63 | $scanner = $this->scannerFactory->getScanner(); |
||
| 64 | $scanner->initAsyncScan(); |
||
| 65 | return CallBackWrapper::wrap( |
||
| 66 | $stream, |
||
| 67 | null, |
||
| 68 | function ($data) use ($scanner){ |
||
| 69 | $scanner->onAsyncData($data); |
||
| 70 | }, |
||
| 71 | function () use ($scanner, $path) { |
||
| 72 | $status = $scanner->completeAsyncScan(); |
||
| 73 | if (intval($status->getNumericStatus()) === \OCA\Files_Antivirus\Status::SCANRESULT_INFECTED){ |
||
| 74 | //prevent from going to trashbin |
||
| 75 | if (App::isEnabled('files_trashbin')) { |
||
| 76 | \OCA\Files_Trashbin\Storage::preRenameHook([]); |
||
| 77 | } |
||
| 78 | |||
| 79 | $owner = $this->getOwner($path); |
||
| 80 | $this->unlink($path); |
||
| 81 | |||
| 82 | if (App::isEnabled('files_trashbin')) { |
||
| 83 | \OCA\Files_Trashbin\Storage::postRenameHook([]); |
||
| 84 | } |
||
| 85 | |||
| 86 | \OC::$server->getActivityManager()->publishActivity( |
||
| 87 | 'files_antivirus', |
||
| 88 | Activity::SUBJECT_VIRUS_DETECTED, |
||
| 89 | [$path, $status->getDetails()], |
||
| 90 | Activity::MESSAGE_FILE_DELETED, |
||
| 91 | [], |
||
| 92 | $path, |
||
| 93 | '', |
||
| 94 | $owner, |
||
| 95 | Activity::TYPE_VIRUS_DETECTED, |
||
| 96 | Activity::PRIORITY_HIGH |
||
| 97 | ); |
||
| 98 | |||
| 99 | throw new InvalidContentException( |
||
| 100 | $this->l10n->t( |
||
| 101 | 'Virus %s is detected in the file. Upload cannot be completed.', |
||
| 102 | $status->getDetails() |
||
| 103 | ) |
||
| 104 | ); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | ); |
||
| 108 | } catch (\Exception $e){ |
||
| 109 | $message = implode(' ', [ __CLASS__, __METHOD__, $e->getMessage()]); |
||
| 110 | $this->logger->warning($message); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | return $stream; |
||
| 114 | } |
||
| 115 | |||
| 131 |