| Conditions | 7 | 
| Paths | 17 | 
| Total Lines | 68 | 
| Code Lines | 49 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 13 | ||
| Bugs | 5 | 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 | ||
| 67 | 	public function run(){ | ||
| 68 | // locate files that are not checked yet | ||
| 69 | 		$dirMimeTypeId = \OC::$server->getMimeTypeLoader()->getId('httpd/unix-directory'); | ||
| 70 | 		try { | ||
| 71 | $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); | ||
| 72 | $qb->select(['fc.fileid']) | ||
| 73 | 				->from('filecache', 'fc') | ||
| 74 | 				->leftJoin('fc', 'files_antivirus', 'fa', $qb->expr()->eq('fa.fileid', 'fc.fileid')) | ||
| 75 | ->innerJoin( | ||
| 76 | 'fc', | ||
| 77 | 'storages', | ||
| 78 | 'ss', | ||
| 79 | $qb->expr()->andX( | ||
| 80 | 						$qb->expr()->eq('fc.storage', 'ss.numeric_id'), | ||
| 81 | $qb->expr()->orX( | ||
| 82 | 							$qb->expr()->like('ss.id', $qb->expr()->literal('local::%')), | ||
| 83 | 							$qb->expr()->like('ss.id', $qb->expr()->literal('home::%')) | ||
| 84 | ) | ||
| 85 | ) | ||
| 86 | ) | ||
| 87 | ->where( | ||
| 88 | 					$qb->expr()->neq('fc.mimetype', $qb->expr()->literal($dirMimeTypeId)) | ||
| 89 | ) | ||
| 90 | ->andWhere( | ||
| 91 | $qb->expr()->orX( | ||
| 92 | 						$qb->expr()->isNull('fa.fileid'), | ||
| 93 | 						$qb->expr()->gt('fc.mtime', 'fa.check_time') | ||
| 94 | ) | ||
| 95 | ) | ||
| 96 | ->andWhere( | ||
| 97 | 					$qb->expr()->like('fc.path', $qb->expr()->literal('files/%')) | ||
| 98 | ) | ||
| 99 | ->andWhere( | ||
| 100 | 					$qb->expr()->neq('fc.size', $qb->expr()->literal('0')) | ||
| 101 | ) | ||
| 102 | ; | ||
| 103 | $result = $qb->execute(); | ||
| 104 | 		} catch(\Exception $e) { | ||
| 105 | \OC::$server->getLogger()->error( __METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); | ||
| 106 | return; | ||
| 107 | } | ||
| 108 | |||
| 109 | $cnt = 0; | ||
| 110 | 		while ($row = $result->fetch() && $cnt < self::BATCH_SIZE) { | ||
|  | |||
| 111 | 			try { | ||
| 112 | $fileId = $row['fileid']; | ||
| 113 | $owner = $this->getOwner($fileId); | ||
| 114 | /** @var IUser $owner */ | ||
| 115 | 				if (!$owner instanceof IUser){ | ||
| 116 | continue; | ||
| 117 | } | ||
| 118 | $this->initFilesystemForUser($owner); | ||
| 119 | $view = Filesystem::getView(); | ||
| 120 | $path = $view->getPath($fileId); | ||
| 121 | 				if (!is_null($path)) { | ||
| 122 | $item = new Item($this->l10n, $view, $path, $fileId); | ||
| 123 | $scanner = $this->scannerFactory->getScanner(); | ||
| 124 | $status = $scanner->scan($item); | ||
| 125 | $status->dispatch($item, true); | ||
| 126 | } | ||
| 127 | // increased only for successfully scanned files | ||
| 128 | $cnt = $cnt + 1; | ||
| 129 | 			} catch (\Exception $e){ | ||
| 130 | \OC::$server->getLogger()->error( __METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | $this->tearDownFilesystem(); | ||
| 134 | } | ||
| 135 | |||
| 194 |