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 |
||
68 | public function run(){ |
||
69 | // locate files that are not checked yet |
||
70 | $dirMimeTypeId = \OC::$server->getMimeTypeLoader()->getId('httpd/unix-directory'); |
||
71 | try { |
||
72 | $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
||
73 | $qb->select(['fc.fileid']) |
||
74 | ->from('filecache', 'fc') |
||
75 | ->leftJoin('fc', 'files_antivirus', 'fa', $qb->expr()->eq('fa.fileid', 'fc.fileid')) |
||
76 | ->innerJoin( |
||
77 | 'fc', |
||
78 | 'storages', |
||
79 | 'ss', |
||
80 | $qb->expr()->andX( |
||
81 | $qb->expr()->eq('fc.storage', 'ss.numeric_id'), |
||
82 | $qb->expr()->orX( |
||
83 | $qb->expr()->like('ss.id', $qb->expr()->literal('local::%')), |
||
84 | $qb->expr()->like('ss.id', $qb->expr()->literal('home::%')) |
||
85 | ) |
||
86 | ) |
||
87 | ) |
||
88 | ->where( |
||
89 | $qb->expr()->neq('fc.mimetype', $qb->expr()->literal($dirMimeTypeId)) |
||
90 | ) |
||
91 | ->andWhere( |
||
92 | $qb->expr()->orX( |
||
93 | $qb->expr()->isNull('fa.fileid'), |
||
94 | $qb->expr()->gt('fc.mtime', 'fa.check_time') |
||
95 | ) |
||
96 | ) |
||
97 | ->andWhere( |
||
98 | $qb->expr()->like('fc.path', $qb->expr()->literal('files/%')) |
||
99 | ) |
||
100 | ->andWhere( |
||
101 | $qb->expr()->neq('fc.size', $qb->expr()->literal('0')) |
||
102 | ) |
||
103 | ; |
||
104 | $result = $qb->execute(); |
||
105 | } catch(\Exception $e) { |
||
106 | \OC::$server->getLogger()->error( __METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); |
||
107 | return; |
||
108 | } |
||
109 | |||
110 | $cnt = 0; |
||
111 | while ($row = $result->fetch() && $cnt++ < self::BATCH_SIZE) { |
||
|
|||
112 | try { |
||
113 | $fileId = $row['fileid']; |
||
114 | $owner = $this->getOwner($fileId); |
||
115 | if (!$owner){ |
||
116 | continue; |
||
117 | } |
||
118 | $this->initFilesystemForUser($owner); |
||
119 | $view = \OC\Files\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 | $this->tearDownFilesystem(); |
||
128 | |||
129 | // increased only for successfully scanned files |
||
130 | $cnt = $cnt + 1; |
||
131 | } catch (\Exception $e){ |
||
132 | \OC::$server->getLogger()->error( __METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | |||
190 |