| Conditions | 9 | 
| Paths | 5 | 
| Total Lines | 69 | 
| Code Lines | 47 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 5 | ||
| 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 | ||
| 69 | 4 | 	public function fopen($path, $mode){ | |
| 70 | 4 | $stream = $this->storage->fopen($path, $mode); | |
| 71 | |||
| 72 | if (is_resource($stream) | ||
| 73 | 2 | && $this->isWritingMode($mode) | |
| 74 | 2 | && $this->isScannableSize() | |
| 75 | 2 | && strpos($path, 'uploads/') !== 0 | |
| 76 | 2 | 		) { | |
| 77 | 2 | 			try { | |
| 78 | $scanner = $this->scannerFactory->getScanner(); | ||
| 79 | 2 | $scanner->initScanner(); | |
| 80 | 2 | return CallBackWrapper::wrap( | |
| 81 | 2 | $stream, | |
| 82 | 2 | null, | |
| 83 | 2 | 					function ($data) use ($scanner){ | |
| 84 | $scanner->onAsyncData($data); | ||
| 85 | 2 | }, | |
| 86 | 2 | 					function () use ($scanner, $path) { | |
| 87 | 2 | $status = $scanner->completeAsyncScan(); | |
| 88 | 						if (intval($status->getNumericStatus()) === \OCA\Files_Antivirus\Status::SCANRESULT_INFECTED){ | ||
| 89 | //prevent from going to trashbin | ||
| 90 | 							if (App::isEnabled('files_trashbin')) { | ||
| 91 | \OCA\Files_Trashbin\Storage::preRenameHook([ | ||
| 92 | 2 | Filesystem::signal_param_oldpath => '', | |
| 93 | 2 | Filesystem::signal_param_newpath => '' | |
| 94 | ]); | ||
| 95 | 2 | } | |
| 96 | 2 | ||
| 97 | $owner = $this->getOwner($path); | ||
| 98 | 2 | $this->unlink($path); | |
| 99 | 2 | ||
| 100 | 2 | 							if (App::isEnabled('files_trashbin')) { | |
| 101 | 2 | \OCA\Files_Trashbin\Storage::postRenameHook([]); | |
| 102 | } | ||
| 103 | $this->logger->warning( | ||
| 104 | 2 | 'Infected file deleted. ' . $status->getDetails() | |
| 105 | 2 | . ' Account: ' . $owner . ' Path: ' . $path, | |
| 106 | 2 | ['app' => 'files_antivirus'] | |
| 107 | 2 | ); | |
| 108 | 2 | ||
| 109 | 2 | \OC::$server->getActivityManager()->publishActivity( | |
| 110 | 2 | 'files_antivirus', | |
| 111 | 2 | Activity::SUBJECT_VIRUS_DETECTED, | |
| 112 | 2 | [$path, $status->getDetails()], | |
| 113 | 2 | Activity::MESSAGE_FILE_DELETED, | |
| 114 | 2 | [], | |
| 115 | $path, | ||
| 116 | '', | ||
| 117 | 2 | $owner, | |
| 118 | 2 | Activity::TYPE_VIRUS_DETECTED, | |
| 119 | 2 | Activity::PRIORITY_HIGH | |
| 120 | 2 | ); | |
| 121 | |||
| 122 | throw new InvalidContentException( | ||
| 123 | $this->l10n->t( | ||
| 124 | 2 | 'Virus %s is detected in the file. Upload cannot be completed.', | |
| 125 | $status->getDetails() | ||
| 126 | 2 | ) | |
| 127 | 2 | ); | |
| 128 | 2 | } | |
| 129 | } | ||
| 130 | ); | ||
| 131 | 4 | 			} catch (\Exception $e){ | |
| 132 | 				$message = 	implode(' ', [ __CLASS__, __METHOD__, $e->getMessage()]); | ||
| 133 | $this->logger->warning($message); | ||
| 134 | } | ||
| 135 | } | ||
| 136 | return $stream; | ||
| 137 | } | ||
| 138 | |||
| 165 |