| Conditions | 19 |
| Paths | 21 |
| Total Lines | 156 |
| Code Lines | 100 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 136 | public function analyze($paths, $mode) |
||
| 137 | { |
||
| 138 | $path = $paths[0]; |
||
| 139 | |||
| 140 | $storage = $this->rootFolder->getUserFolder($this->userId)->get(dirname($path))->getStorage(); |
||
| 141 | if ($this->userId === null || $this->nestingLevel !== 0 || /*!$this->isUploadedFile($storage, $path) ||*/ $this->isCreatingSkeletonFiles()) { |
||
| 142 | // check only cloud files and no system files |
||
| 143 | return; |
||
| 144 | } |
||
| 145 | |||
| 146 | if (!$this->request->isUserAgent([ |
||
| 147 | IRequest::USER_AGENT_CLIENT_DESKTOP, |
||
| 148 | IRequest::USER_AGENT_CLIENT_ANDROID, |
||
| 149 | IRequest::USER_AGENT_CLIENT_IOS, |
||
| 150 | ])) { |
||
| 151 | // not a sync client |
||
| 152 | return; |
||
| 153 | } |
||
| 154 | |||
| 155 | $this->nestingLevel++; |
||
| 156 | |||
| 157 | switch ($mode) { |
||
| 158 | case self::RENAME: |
||
| 159 | $path = $paths[1]; |
||
| 160 | $this->logger->debug("Rename ".$paths[0]." to ".$paths[1], ['app' => Application::APP_ID]); |
||
| 161 | if (preg_match('/.+\.d[0-9]+/', pathinfo($paths[1])['basename']) > 0) { |
||
| 162 | return; |
||
| 163 | } |
||
| 164 | // reset PROPFIND_COUNT |
||
| 165 | $this->resetProfindCount(); |
||
| 166 | |||
| 167 | try { |
||
| 168 | $userRoot = $this->rootFolder->getUserFolder($this->userId); |
||
| 169 | $node = $userRoot->get($path); |
||
| 170 | } catch (\OCP\Files\NotFoundException $exception) { |
||
| 171 | $this->logger->error("File Not Found ".$path, ['app' => Application::APP_ID]); |
||
| 172 | return; |
||
| 173 | } |
||
| 174 | |||
| 175 | // not a file no need to analyze |
||
| 176 | if (!($node instanceof File)) { |
||
| 177 | $this->addFolderOperation($paths, $node, self::RENAME); |
||
| 178 | $this->nestingLevel--; |
||
| 179 | |||
| 180 | return; |
||
| 181 | } |
||
| 182 | |||
| 183 | $this->addFileOperation($paths, $node, self::RENAME); |
||
| 184 | |||
| 185 | $this->nestingLevel--; |
||
| 186 | |||
| 187 | return; |
||
| 188 | case self::WRITE: |
||
| 189 | $this->logger->debug("Write ".$path, ['app' => Application::APP_ID]); |
||
| 190 | // reset PROPFIND_COUNT |
||
| 191 | $this->resetProfindCount(); |
||
| 192 | |||
| 193 | try { |
||
| 194 | $userRoot = $this->rootFolder->getUserFolder($this->userId); |
||
| 195 | $node = $userRoot->get($path); |
||
| 196 | } catch (\OCP\Files\NotFoundException $exception) { |
||
| 197 | $this->logger->error("File Not Found ".$path, ['app' => Application::APP_ID]); |
||
| 198 | return; |
||
| 199 | } |
||
| 200 | |||
| 201 | // not a file no need to analyze |
||
| 202 | if (!($node instanceof File)) { |
||
| 203 | $this->addFolderOperation($paths, $node, self::WRITE); |
||
| 204 | $this->nestingLevel--; |
||
| 205 | |||
| 206 | return; |
||
| 207 | } |
||
| 208 | |||
| 209 | $this->addFileOperation($paths, $node, self::WRITE); |
||
| 210 | |||
| 211 | $this->nestingLevel--; |
||
| 212 | |||
| 213 | return; |
||
| 214 | case self::READ: |
||
| 215 | $this->nestingLevel--; |
||
| 216 | |||
| 217 | return; |
||
| 218 | case self::DELETE: |
||
| 219 | $this->logger->debug("Delete", ['app' => Application::APP_ID]); |
||
| 220 | // reset PROPFIND_COUNT |
||
| 221 | $this->resetProfindCount(); |
||
| 222 | |||
| 223 | try { |
||
| 224 | $userRoot = $this->rootFolder->getUserFolder($this->userId); |
||
| 225 | $node = $userRoot->get($path); |
||
| 226 | } catch (\OCP\Files\NotFoundException $exception) { |
||
| 227 | $this->logger->error("File Not Found ".$path, ['app' => Application::APP_ID]); |
||
| 228 | return; |
||
| 229 | } |
||
| 230 | |||
| 231 | // not a file no need to analyze |
||
| 232 | if (!($node instanceof File)) { |
||
| 233 | $this->addFolderOperation($paths, $node, self::DELETE); |
||
| 234 | $this->nestingLevel--; |
||
| 235 | |||
| 236 | return; |
||
| 237 | } |
||
| 238 | |||
| 239 | $this->addFileOperation($paths, $node, self::DELETE); |
||
| 240 | |||
| 241 | $this->nestingLevel--; |
||
| 242 | |||
| 243 | return; |
||
| 244 | case self::CREATE: |
||
| 245 | $this->logger->debug("Create", ['app' => Application::APP_ID]); |
||
| 246 | // reset PROPFIND_COUNT |
||
| 247 | $this->resetProfindCount(); |
||
| 248 | |||
| 249 | try { |
||
| 250 | $userRoot = $this->rootFolder->getUserFolder($this->userId); |
||
| 251 | $node = $userRoot->get($path); |
||
| 252 | } catch (\OCP\Files\NotFoundException $exception) { |
||
| 253 | $this->logger->error("File Not Found ".$path, ['app' => Application::APP_ID]); |
||
| 254 | return; |
||
| 255 | } |
||
| 256 | if (!($node instanceof File)) { |
||
| 257 | |||
| 258 | $fileOperation = new FileOperation(); |
||
| 259 | $fileOperation->setUserId($this->userId); |
||
| 260 | $fileOperation->setPath(str_replace('files', '', pathinfo($path)['dirname'])); |
||
| 261 | $fileOperation->setOriginalName(pathinfo($path)['basename']); |
||
| 262 | $fileOperation->setType('folder'); |
||
| 263 | $fileOperation->setMimeType('httpd/unix-directory'); |
||
| 264 | $fileOperation->setSize(0); |
||
| 265 | $fileOperation->setTimestamp(time()); |
||
| 266 | $fileOperation->setCorrupted(false); |
||
| 267 | $fileOperation->setCommand(self::CREATE); |
||
| 268 | $sequenceId = $this->config->getUserValue($this->userId, Application::APP_ID, 'sequence_id', 0); |
||
| 269 | $fileOperation->setSequence($sequenceId); |
||
| 270 | |||
| 271 | // entropy analysis |
||
| 272 | $fileOperation->setEntropy(0.0); |
||
| 273 | $fileOperation->setStandardDeviation(0.0); |
||
| 274 | $fileOperation->setFileClass(EntropyResult::NORMAL); |
||
| 275 | |||
| 276 | // file extension analysis |
||
| 277 | $fileOperation->setFileExtensionClass(FileExtensionResult::NOT_SUSPICIOUS); |
||
| 278 | |||
| 279 | $this->mapper->insert($fileOperation); |
||
| 280 | $this->nestingLevel--; |
||
| 281 | } else { |
||
| 282 | $this->addFileOperation($paths, $node, self::CREATE); |
||
| 283 | |||
| 284 | $this->nestingLevel--; |
||
| 285 | } |
||
| 286 | |||
| 287 | return; |
||
| 288 | default: |
||
| 289 | $this->nestingLevel--; |
||
| 290 | |||
| 291 | return; |
||
| 292 | } |
||
| 478 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths