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