| Conditions | 7 |
| Paths | 19 |
| Total Lines | 68 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 12 | ||
| 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 | if (!$owner){ |
||
| 115 | continue; |
||
| 116 | } |
||
| 117 | $this->initFilesystemForUser($owner); |
||
| 118 | $view = \OC\Files\Filesystem::getView(); |
||
| 119 | $path = $view->getPath($fileId); |
||
| 120 | if (!is_null($path)) { |
||
| 121 | $item = new Item($this->l10n, $view, $path, $fileId); |
||
| 122 | $scanner = $this->scannerFactory->getScanner(); |
||
| 123 | $status = $scanner->scan($item); |
||
| 124 | $status->dispatch($item, true); |
||
| 125 | } |
||
| 126 | $this->tearDownFilesystem(); |
||
| 127 | |||
| 128 | // increased only for successfully scanned files |
||
| 129 | $cnt = $cnt + 1; |
||
| 130 | } catch (\Exception $e){ |
||
| 131 | \OC::$server->getLogger()->error( __METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 189 |