| Conditions | 6 |
| Paths | 16 |
| Total Lines | 63 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 10 | ||
| Bugs | 4 | 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 |
||
| 49 | public function run(){ |
||
| 50 | if (!$this->initFS()) { |
||
| 51 | return; |
||
| 52 | } |
||
| 53 | // locate files that are not checked yet |
||
| 54 | $dirMimeTypeId = \OC::$server->getMimeTypeLoader()->getId('httpd/unix-directory'); |
||
| 55 | try { |
||
| 56 | $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
||
| 57 | $qb->select(['fc.fileid']) |
||
| 58 | ->from('filecache', 'fc') |
||
| 59 | ->leftJoin('fc', 'files_antivirus', 'fa', $qb->expr()->eq('fa.fileid', 'fc.fileid')) |
||
| 60 | ->innerJoin( |
||
| 61 | 'fc', |
||
| 62 | 'storages', |
||
| 63 | 'ss', |
||
| 64 | $qb->expr()->andX( |
||
| 65 | $qb->expr()->eq('fc.storage', 'ss.numeric_id'), |
||
| 66 | $qb->expr()->orX( |
||
| 67 | $qb->expr()->like('ss.id', $qb->expr()->literal('local::%')), |
||
| 68 | $qb->expr()->like('ss.id', $qb->expr()->literal('home::%')) |
||
| 69 | ) |
||
| 70 | ) |
||
| 71 | ) |
||
| 72 | ->where( |
||
| 73 | $qb->expr()->neq('fc.mimetype', $qb->expr()->literal($dirMimeTypeId)) |
||
| 74 | ) |
||
| 75 | ->andWhere( |
||
| 76 | $qb->expr()->orX( |
||
| 77 | $qb->expr()->isNull('fa.fileid'), |
||
| 78 | $qb->expr()->gt('fc.mtime', 'fa.check_time') |
||
| 79 | ) |
||
| 80 | ) |
||
| 81 | ->andWhere( |
||
| 82 | $qb->expr()->like('fc.path', $qb->expr()->literal('files/%')) |
||
| 83 | ) |
||
| 84 | ->andWhere( |
||
| 85 | $qb->expr()->neq('fc.size', '?1') |
||
| 86 | ) |
||
| 87 | ->setMaxResults(5) |
||
| 88 | ; |
||
| 89 | $result = $qb->execute([0]); |
||
| 90 | } catch(\Exception $e) { |
||
| 91 | \OC::$server->getLogger()->error( __METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); |
||
| 92 | return; |
||
| 93 | } |
||
| 94 | |||
| 95 | |||
| 96 | $view = new \OC\Files\View(''); |
||
| 97 | try { |
||
| 98 | while ($row = $result->fetch()) { |
||
| 99 | $path = $view->getPath($row['fileid']); |
||
| 100 | if (!is_null($path)) { |
||
| 101 | $item = new Item($this->l10n, $view, $path, $row['fileid']); |
||
| 102 | $scanner = $this->scannerFactory->getScanner(); |
||
| 103 | $status = $scanner->scan($item); |
||
| 104 | $status->dispatch($item, true); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | } catch (\Exception $e){ |
||
| 108 | \OC::$server->getLogger()->error( __METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); |
||
| 109 | } |
||
| 110 | \OC_Util::tearDownFS(); |
||
| 111 | } |
||
| 112 | |||
| 137 |