Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like FilesService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FilesService, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 58 | class FilesService { |
||
| 59 | |||
| 60 | const MIMETYPE_TEXT = 'files_text'; |
||
| 61 | const MIMETYPE_PDF = 'files_pdf'; |
||
| 62 | const MIMETYPE_OFFICE = 'files_office'; |
||
| 63 | const MIMETYPE_OCR = 'files_ocr'; |
||
| 64 | const MIMETYPE_IMAGE = 'files_image'; |
||
| 65 | const MIMETYPE_AUDIO = 'files_audio'; |
||
| 66 | |||
| 67 | |||
| 68 | /** @var IAppContainer */ |
||
| 69 | private $container; |
||
| 70 | |||
| 71 | /** @var IRootFolder */ |
||
| 72 | private $rootFolder; |
||
| 73 | |||
| 74 | /** @var IUserManager */ |
||
| 75 | private $userManager; |
||
| 76 | |||
| 77 | /** @var AppManager */ |
||
| 78 | private $appManager; |
||
| 79 | |||
| 80 | /** @var IManager */ |
||
| 81 | private $shareManager; |
||
| 82 | |||
| 83 | /** @var ConfigService */ |
||
| 84 | private $configService; |
||
| 85 | |||
| 86 | /** @var LocalFilesService */ |
||
| 87 | private $localFilesService; |
||
| 88 | |||
| 89 | /** @var ExternalFilesService */ |
||
| 90 | private $externalFilesService; |
||
| 91 | |||
| 92 | /** @var GroupFoldersService */ |
||
| 93 | private $groupFoldersService; |
||
| 94 | |||
| 95 | /** @var ExtensionService */ |
||
| 96 | private $extensionService; |
||
| 97 | |||
| 98 | /** @var MiscService */ |
||
| 99 | private $miscService; |
||
| 100 | |||
| 101 | |||
| 102 | /** |
||
| 103 | * FilesService constructor. |
||
| 104 | * |
||
| 105 | * @param IAppContainer $container |
||
| 106 | * @param IRootFolder $rootFolder |
||
| 107 | * @param AppManager $appManager |
||
| 108 | * @param IUserManager $userManager |
||
| 109 | * @param IManager $shareManager |
||
| 110 | * @param ConfigService $configService |
||
| 111 | * @param LocalFilesService $localFilesService |
||
| 112 | * @param ExternalFilesService $externalFilesService |
||
| 113 | * @param GroupFoldersService $groupFoldersService |
||
| 114 | * @param ExtensionService $extensionService |
||
| 115 | * @param MiscService $miscService |
||
| 116 | * |
||
| 117 | * @internal param IProviderFactory $factory |
||
| 118 | */ |
||
| 119 | public function __construct( |
||
| 120 | IAppContainer $container, IRootFolder $rootFolder, AppManager $appManager, |
||
| 121 | IUserManager $userManager, IManager $shareManager, |
||
| 122 | ConfigService $configService, LocalFilesService $localFilesService, |
||
| 123 | ExternalFilesService $externalFilesService, GroupFoldersService $groupFoldersService, |
||
| 124 | ExtensionService $extensionService, MiscService $miscService |
||
| 125 | ) { |
||
| 126 | $this->container = $container; |
||
| 127 | $this->rootFolder = $rootFolder; |
||
| 128 | $this->appManager = $appManager; |
||
| 129 | $this->userManager = $userManager; |
||
| 130 | $this->shareManager = $shareManager; |
||
| 131 | |||
| 132 | $this->configService = $configService; |
||
| 133 | $this->localFilesService = $localFilesService; |
||
| 134 | $this->externalFilesService = $externalFilesService; |
||
| 135 | $this->groupFoldersService = $groupFoldersService; |
||
| 136 | $this->extensionService = $extensionService; |
||
| 137 | |||
| 138 | $this->miscService = $miscService; |
||
| 139 | } |
||
| 140 | |||
| 141 | |||
| 142 | /** |
||
| 143 | * @param Runner $runner |
||
| 144 | * @param string $userId |
||
| 145 | * @param IndexOptions $indexOptions |
||
| 146 | * |
||
| 147 | * @return FilesDocument[] |
||
| 148 | * @throws InterruptException |
||
| 149 | * @throws InvalidPathException |
||
| 150 | * @throws NotFoundException |
||
| 151 | * @throws TickDoesNotExistException |
||
| 152 | */ |
||
| 153 | public function getFilesFromUser(Runner $runner, $userId, $indexOptions) { |
||
| 154 | |||
| 155 | $this->initFileSystems($userId); |
||
| 156 | |||
| 157 | /** @var Folder $files */ |
||
| 158 | $files = $this->rootFolder->getUserFolder($userId) |
||
| 159 | ->get($indexOptions->getOption('path', '/')); |
||
| 160 | |||
| 161 | if ($files instanceof Folder) { |
||
|
|
|||
| 162 | $result = $this->getFilesFromDirectory($runner, $userId, $files); |
||
| 163 | } else { |
||
| 164 | $result = []; |
||
| 165 | try { |
||
| 166 | $result[] = $this->generateFilesDocumentFromFile($userId, $files); |
||
| 167 | } catch (FileIsNotIndexableException $e) { |
||
| 168 | /** we do nothin' */ |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | return $result; |
||
| 173 | } |
||
| 174 | |||
| 175 | |||
| 176 | /** |
||
| 177 | * @param string $userId |
||
| 178 | */ |
||
| 179 | private function initFileSystems($userId) { |
||
| 180 | if ($userId === '') { |
||
| 181 | return; |
||
| 182 | } |
||
| 183 | |||
| 184 | $this->externalFilesService->initExternalFilesForUser($userId); |
||
| 185 | $this->groupFoldersService->initGroupSharesForUser($userId); |
||
| 186 | } |
||
| 187 | |||
| 188 | |||
| 189 | /** |
||
| 190 | * @param Runner $runner |
||
| 191 | * @param string $userId |
||
| 192 | * @param Folder $node |
||
| 193 | * |
||
| 194 | * @return FilesDocument[] |
||
| 195 | * @throws InterruptException |
||
| 196 | * @throws InvalidPathException |
||
| 197 | * @throws NotFoundException |
||
| 198 | * @throws TickDoesNotExistException |
||
| 199 | */ |
||
| 200 | public function getFilesFromDirectory(Runner $runner, $userId, Folder $node) { |
||
| 201 | $documents = []; |
||
| 202 | |||
| 203 | try { |
||
| 204 | if ($node->nodeExists('.noindex')) { |
||
| 205 | return $documents; |
||
| 206 | } |
||
| 207 | } catch (StorageNotAvailableException $e) { |
||
| 208 | return $documents; |
||
| 209 | } |
||
| 210 | |||
| 211 | $files = $node->getDirectoryListing(); |
||
| 212 | foreach ($files as $file) { |
||
| 213 | $runner->updateAction('getFilesFromDirectory'); |
||
| 214 | |||
| 215 | try { |
||
| 216 | $documents[] = $this->generateFilesDocumentFromFile($userId, $file); |
||
| 217 | } catch (FileIsNotIndexableException $e) { |
||
| 218 | continue; |
||
| 219 | } |
||
| 220 | |||
| 221 | if ($file->getType() === FileInfo::TYPE_FOLDER) { |
||
| 222 | /** @var $file Folder */ |
||
| 223 | $documents = |
||
| 224 | array_merge($documents, $this->getFilesFromDirectory($runner, $userId, $file)); |
||
| 225 | } |
||
| 226 | } |
||
| 227 | |||
| 228 | return $documents; |
||
| 229 | } |
||
| 230 | |||
| 231 | |||
| 232 | /** |
||
| 233 | * @param Node $file |
||
| 234 | * |
||
| 235 | * @param string $viewerId |
||
| 236 | * |
||
| 237 | * @return FilesDocument |
||
| 238 | * @throws FileIsNotIndexableException |
||
| 239 | * @throws InvalidPathException |
||
| 240 | * @throws NotFoundException |
||
| 241 | * @throws Exception |
||
| 242 | */ |
||
| 243 | private function generateFilesDocumentFromFile($viewerId, Node $file) { |
||
| 244 | |||
| 245 | $source = $this->getFileSource($file); |
||
| 246 | $document = new FilesDocument(FilesProvider::FILES_PROVIDER_ID, $file->getId()); |
||
| 247 | |||
| 248 | $ownerId = ''; |
||
| 249 | if ($file->getOwner() !== null) { |
||
| 250 | $ownerId = $file->getOwner() |
||
| 251 | ->getUID(); |
||
| 252 | } |
||
| 253 | $document->setType($file->getType()) |
||
| 254 | ->setSource($source) |
||
| 255 | ->setOwnerId($ownerId) |
||
| 256 | ->setPath($this->getPathFromViewerId($file->getId(), $viewerId)) |
||
| 257 | ->setViewerId($viewerId) |
||
| 258 | ->setModifiedTime($file->getMTime()) |
||
| 259 | ->setMimetype($file->getMimetype()); |
||
| 260 | |||
| 261 | return $document; |
||
| 262 | } |
||
| 263 | |||
| 264 | |||
| 265 | /** |
||
| 266 | * @param Node $file |
||
| 267 | * |
||
| 268 | * @return string |
||
| 269 | * @throws FileIsNotIndexableException |
||
| 270 | * @throws NotFoundException |
||
| 271 | */ |
||
| 272 | private function getFileSource(Node $file) { |
||
| 273 | $source = ''; |
||
| 274 | |||
| 275 | try { |
||
| 276 | $this->localFilesService->getFileSource($file, $source); |
||
| 277 | $this->externalFilesService->getFileSource($file, $source); |
||
| 278 | $this->groupFoldersService->getFileSource($file, $source); |
||
| 279 | } catch (KnownFileSourceException $e) { |
||
| 280 | /** we know the source, just leave. */ |
||
| 281 | } |
||
| 282 | |||
| 283 | return $source; |
||
| 284 | } |
||
| 285 | |||
| 286 | |||
| 287 | /** |
||
| 288 | * @param string $userId |
||
| 289 | * @param string $path |
||
| 290 | * |
||
| 291 | * @return Node |
||
| 292 | * @throws NotFoundException |
||
| 293 | */ |
||
| 294 | public function getFileFromPath($userId, $path) { |
||
| 295 | return $this->rootFolder->getUserFolder($userId) |
||
| 296 | ->get($path); |
||
| 297 | } |
||
| 298 | |||
| 299 | |||
| 300 | /** |
||
| 301 | * @param string $userId |
||
| 302 | * @param int $fileId |
||
| 303 | * |
||
| 304 | * @return Node |
||
| 305 | * @throws FilesNotFoundException |
||
| 306 | * @throws EmptyUserException |
||
| 307 | */ |
||
| 308 | public function getFileFromId($userId, $fileId) { |
||
| 309 | |||
| 310 | if ($userId === '') { |
||
| 311 | throw new EmptyUserException(); |
||
| 312 | } |
||
| 313 | |||
| 314 | $files = $this->rootFolder->getUserFolder($userId) |
||
| 315 | ->getById($fileId); |
||
| 316 | if (sizeof($files) === 0) { |
||
| 317 | throw new FilesNotFoundException(); |
||
| 318 | } |
||
| 319 | |||
| 320 | $file = array_shift($files); |
||
| 321 | |||
| 322 | return $file; |
||
| 323 | } |
||
| 324 | |||
| 325 | |||
| 326 | /** |
||
| 327 | * @param Index $index |
||
| 328 | * |
||
| 329 | * @return Node |
||
| 330 | * @throws EmptyUserException |
||
| 331 | * @throws FilesNotFoundException |
||
| 332 | */ |
||
| 333 | public function getFileFromIndex(Index $index) { |
||
| 334 | $this->impersonateOwner($index); |
||
| 335 | |||
| 336 | return $this->getFileFromId($index->getOwnerId(), $index->getDocumentId()); |
||
| 337 | } |
||
| 338 | |||
| 339 | |||
| 340 | /** |
||
| 341 | * @param int $fileId |
||
| 342 | * @param string $viewerId |
||
| 343 | * |
||
| 344 | * @throws Exception |
||
| 345 | * @return string |
||
| 346 | */ |
||
| 347 | private function getPathFromViewerId($fileId, $viewerId) { |
||
| 348 | |||
| 349 | $viewerFiles = $this->rootFolder->getUserFolder($viewerId) |
||
| 350 | ->getById($fileId); |
||
| 351 | |||
| 352 | if (sizeof($viewerFiles) === 0) { |
||
| 353 | return ''; |
||
| 354 | } |
||
| 355 | |||
| 356 | $file = array_shift($viewerFiles); |
||
| 357 | |||
| 358 | // TODO: better way to do this : we remove the '/userid/files/' |
||
| 359 | $path = MiscService::noEndSlash(substr($file->getPath(), 8 + strlen($viewerId))); |
||
| 360 | |||
| 361 | return $path; |
||
| 362 | } |
||
| 363 | |||
| 364 | |||
| 365 | /** |
||
| 366 | * @param FilesDocument $document |
||
| 367 | */ |
||
| 368 | public function generateDocument(FilesDocument $document) { |
||
| 369 | |||
| 370 | try { |
||
| 371 | $this->updateFilesDocument($document); |
||
| 372 | } catch (Exception $e) { |
||
| 373 | // TODO - update $document with a error status instead of just ignore ! |
||
| 374 | $document->getIndex() |
||
| 375 | ->setStatus(Index::INDEX_IGNORE); |
||
| 376 | echo 'Exception: ' . json_encode($e->getTrace()) . ' - ' . $e->getMessage() |
||
| 377 | . "\n"; |
||
| 378 | } |
||
| 379 | } |
||
| 380 | |||
| 381 | |||
| 382 | /** |
||
| 383 | * @param Index $index |
||
| 384 | * |
||
| 385 | * @return FilesDocument |
||
| 386 | * @throws FileIsNotIndexableException |
||
| 387 | * @throws InvalidPathException |
||
| 388 | * @throws NotFoundException |
||
| 389 | * @throws NotPermittedException |
||
| 390 | */ |
||
| 391 | private function generateDocumentFromIndex(Index $index) { |
||
| 392 | |||
| 393 | try { |
||
| 394 | $file = $this->getFileFromIndex($index); |
||
| 395 | } catch (Exception $e) { |
||
| 396 | $index->setStatus(Index::INDEX_REMOVE); |
||
| 397 | $document = new FilesDocument($index->getProviderId(), $index->getDocumentId()); |
||
| 398 | $document->setIndex($index); |
||
| 399 | |||
| 400 | return $document; |
||
| 401 | } |
||
| 402 | |||
| 403 | $document = $this->generateFilesDocumentFromFile($index->getOwnerId(), $file); |
||
| 404 | $document->setIndex($index); |
||
| 405 | |||
| 406 | $this->updateFilesDocumentFromFile($document, $file); |
||
| 407 | |||
| 408 | return $document; |
||
| 409 | } |
||
| 410 | |||
| 411 | |||
| 412 | /** |
||
| 413 | * @param IndexDocument $document |
||
| 414 | * |
||
| 415 | * @return bool |
||
| 416 | */ |
||
| 417 | public function isDocumentUpToDate($document) { |
||
| 418 | $index = $document->getIndex(); |
||
| 419 | |||
| 420 | if (!$this->configService->compareIndexOptions($index)) { |
||
| 421 | $index->setStatus(Index::INDEX_CONTENT); |
||
| 422 | $document->setIndex($index); |
||
| 423 | |||
| 424 | return false; |
||
| 425 | } |
||
| 426 | |||
| 427 | if ($index->getStatus() !== Index::INDEX_OK) { |
||
| 428 | return false; |
||
| 429 | } |
||
| 430 | |||
| 431 | if ($index->getLastIndex() >= $document->getModifiedTime()) { |
||
| 432 | return true; |
||
| 433 | } |
||
| 434 | |||
| 435 | return false; |
||
| 436 | } |
||
| 437 | |||
| 438 | |||
| 439 | /** |
||
| 440 | * @param Index $index |
||
| 441 | * |
||
| 442 | * @return FilesDocument |
||
| 443 | * @throws InvalidPathException |
||
| 444 | * @throws NotFoundException |
||
| 445 | * @throws NotPermittedException |
||
| 446 | * @throws FileIsNotIndexableException |
||
| 447 | */ |
||
| 448 | public function updateDocument(Index $index) { |
||
| 449 | $this->impersonateOwner($index); |
||
| 450 | $this->initFileSystems($index->getOwnerId()); |
||
| 451 | |||
| 452 | return $this->generateDocumentFromIndex($index); |
||
| 453 | } |
||
| 454 | |||
| 455 | |||
| 456 | /** |
||
| 457 | * @param FilesDocument $document |
||
| 458 | * |
||
| 459 | * @throws InvalidPathException |
||
| 460 | * @throws NotFoundException |
||
| 461 | * @throws NotPermittedException |
||
| 462 | */ |
||
| 463 | private function updateFilesDocument(FilesDocument $document) { |
||
| 464 | $userFolder = $this->rootFolder->getUserFolder($document->getViewerId()); |
||
| 465 | $file = $userFolder->get($document->getPath()); |
||
| 466 | |||
| 467 | try { |
||
| 468 | $this->updateFilesDocumentFromFile($document, $file); |
||
| 469 | } catch (FileIsNotIndexableException $e) { |
||
| 470 | $document->getIndex() |
||
| 471 | ->setStatus(Index::INDEX_IGNORE); |
||
| 472 | } |
||
| 473 | } |
||
| 474 | |||
| 475 | |||
| 476 | /** |
||
| 477 | * @param FilesDocument $document |
||
| 478 | * @param Node $file |
||
| 479 | * |
||
| 480 | * @throws InvalidPathException |
||
| 481 | * @throws NotFoundException |
||
| 482 | * @throws NotPermittedException |
||
| 483 | */ |
||
| 484 | private function updateFilesDocumentFromFile(FilesDocument $document, Node $file) { |
||
| 485 | |||
| 486 | $document->getIndex() |
||
| 487 | ->setSource($document->getSource()); |
||
| 488 | |||
| 489 | $this->updateDocumentAccess($document, $file); |
||
| 490 | $this->updateContentFromFile($document, $file); |
||
| 491 | |||
| 492 | $document->addMetaTag($document->getSource()); |
||
| 493 | |||
| 494 | $this->extensionService->fileIndexing($document, $file); |
||
| 495 | } |
||
| 496 | |||
| 497 | |||
| 498 | /** |
||
| 499 | * @param FilesDocument $document |
||
| 500 | * @param Node $file |
||
| 501 | */ |
||
| 502 | private function updateDocumentAccess(FilesDocument $document, Node $file) { |
||
| 503 | |||
| 504 | $index = $document->getIndex(); |
||
| 505 | |||
| 506 | if (!$index->isStatus(Index::INDEX_FULL) |
||
| 507 | && !$index->isStatus(FilesDocument::STATUS_FILE_ACCESS)) { |
||
| 508 | return; |
||
| 509 | } |
||
| 510 | |||
| 511 | $this->localFilesService->updateDocumentAccess($document, $file); |
||
| 512 | $this->externalFilesService->updateDocumentAccess($document, $file); |
||
| 513 | $this->groupFoldersService->updateDocumentAccess($document, $file); |
||
| 514 | |||
| 515 | $this->updateShareNames($document, $file); |
||
| 516 | } |
||
| 517 | |||
| 518 | |||
| 519 | /** |
||
| 520 | * @param FilesDocument $document |
||
| 521 | * @param Node $file |
||
| 522 | * |
||
| 523 | * @throws InvalidPathException |
||
| 524 | * @throws NotFoundException |
||
| 525 | * @throws NotPermittedException |
||
| 526 | */ |
||
| 527 | private function updateContentFromFile(FilesDocument $document, Node $file) { |
||
| 528 | |||
| 529 | $document->setTitle($document->getPath()); |
||
| 530 | |||
| 531 | if (!$document->getIndex() |
||
| 532 | ->isStatus(Index::INDEX_CONTENT) |
||
| 533 | || $file->getType() !== FileInfo::TYPE_FILE) { |
||
| 534 | return; |
||
| 535 | } |
||
| 536 | |||
| 537 | /** @var File $file */ |
||
| 538 | if ($file->getSize() < |
||
| 539 | ($this->configService->getAppValue(ConfigService::FILES_SIZE) * 1024 * 1024)) { |
||
| 540 | $this->extractContentFromFileText($document, $file); |
||
| 541 | $this->extractContentFromFileOffice($document, $file); |
||
| 542 | $this->extractContentFromFilePDF($document, $file); |
||
| 543 | } |
||
| 544 | |||
| 545 | if ($document->getContent() === null) { |
||
| 546 | $document->getIndex() |
||
| 547 | ->unsetStatus(Index::INDEX_CONTENT); |
||
| 548 | } |
||
| 549 | } |
||
| 550 | |||
| 551 | |||
| 552 | /** |
||
| 553 | * @param FilesDocument $document |
||
| 554 | * @param Node $file |
||
| 555 | * |
||
| 556 | * @return array |
||
| 557 | */ |
||
| 558 | private function updateShareNames(FilesDocument $document, Node $file) { |
||
| 559 | |||
| 560 | $users = []; |
||
| 561 | |||
| 562 | $this->localFilesService->getShareUsersFromFile($file, $users); |
||
| 563 | $this->externalFilesService->getShareUsers($document, $users); |
||
| 564 | $this->groupFoldersService->getShareUsers($document, $users); |
||
| 565 | |||
| 566 | $shareNames = []; |
||
| 567 | foreach ($users as $username) { |
||
| 568 | try { |
||
| 569 | $user = $this->userManager->get($username); |
||
| 570 | if ($user === null || $user->getLastLogin() === 0) { |
||
| 571 | continue; |
||
| 572 | } |
||
| 573 | |||
| 574 | $path = $this->getPathFromViewerId($file->getId(), $username); |
||
| 575 | $shareNames[MiscService::secureUsername($username)] = |
||
| 576 | (!is_string($path)) ? $path = '' : $path; |
||
| 577 | |||
| 578 | } catch (Exception $e) { |
||
| 579 | $this->miscService->log( |
||
| 580 | 'Issue while getting information on documentId:' . $document->getId(), 0 |
||
| 581 | ); |
||
| 582 | } |
||
| 583 | } |
||
| 584 | |||
| 585 | $document->setInfo('share_names', $shareNames); |
||
| 586 | |||
| 587 | return $shareNames; |
||
| 588 | } |
||
| 589 | |||
| 590 | |||
| 591 | /** |
||
| 592 | * @param string $mimeType |
||
| 593 | * |
||
| 594 | * @return string |
||
| 595 | */ |
||
| 596 | private function parseMimeType($mimeType) { |
||
| 597 | |||
| 598 | $parsed = ''; |
||
| 599 | try { |
||
| 600 | $this->parseMimeTypeText($mimeType, $parsed); |
||
| 601 | $this->parseMimeTypePDF($mimeType, $parsed); |
||
| 602 | $this->parseMimeTypeOffice($mimeType, $parsed); |
||
| 603 | } catch (KnownFileMimeTypeException $e) { |
||
| 604 | } |
||
| 605 | |||
| 606 | return $parsed; |
||
| 607 | } |
||
| 608 | |||
| 609 | |||
| 610 | /** |
||
| 611 | * @param string $mimeType |
||
| 612 | * @param string $parsed |
||
| 613 | * |
||
| 614 | * @throws KnownFileMimeTypeException |
||
| 615 | */ |
||
| 616 | private function parseMimeTypeText($mimeType, &$parsed) { |
||
| 634 | |||
| 635 | |||
| 636 | /** |
||
| 637 | * @param string $mimeType |
||
| 638 | * @param string $parsed |
||
| 639 | * |
||
| 640 | * @throws KnownFileMimeTypeException |
||
| 641 | */ |
||
| 642 | private function parseMimeTypePDF($mimeType, &$parsed) { |
||
| 649 | |||
| 650 | |||
| 651 | /** |
||
| 652 | * @param string $mimeType |
||
| 653 | * @param string $parsed |
||
| 654 | * |
||
| 655 | * @throws KnownFileMimeTypeException |
||
| 656 | */ |
||
| 657 | private function parseMimeTypeOffice($mimeType, &$parsed) { |
||
| 676 | |||
| 677 | |||
| 678 | /** |
||
| 679 | * @param FilesDocument $document |
||
| 680 | * @param File $file |
||
| 681 | * |
||
| 682 | * @throws NotPermittedException |
||
| 683 | */ |
||
| 684 | private function extractContentFromFileText(FilesDocument $document, File $file) { |
||
| 698 | |||
| 699 | |||
| 700 | /** |
||
| 701 | * @param FilesDocument $document |
||
| 702 | * @param File $file |
||
| 703 | * |
||
| 704 | * @throws NotPermittedException |
||
| 705 | */ |
||
| 706 | View Code Duplication | private function extractContentFromFilePDF(FilesDocument $document, File $file) { |
|
| 726 | |||
| 727 | |||
| 728 | /** |
||
| 729 | * @param FilesDocument $document |
||
| 730 | * @param File $file |
||
| 731 | * |
||
| 732 | * @throws NotPermittedException |
||
| 733 | */ |
||
| 734 | View Code Duplication | private function extractContentFromFileOffice(FilesDocument $document, File $file) { |
|
| 754 | |||
| 755 | |||
| 756 | /** |
||
| 757 | * @param FilesDocument $document |
||
| 758 | * |
||
| 759 | * @return bool |
||
| 760 | */ |
||
| 761 | private function isSourceIndexable(FilesDocument $document) { |
||
| 762 | $this->configService->setDocumentIndexOption($document, $document->getSource()); |
||
| 763 | if ($this->configService->getAppValue($document->getSource()) !== '1') { |
||
| 764 | $document->setContent(''); |
||
| 765 | |||
| 766 | return false; |
||
| 767 | } |
||
| 768 | |||
| 769 | return true; |
||
| 770 | } |
||
| 771 | |||
| 772 | |||
| 773 | private function impersonateOwner(Index $index) { |
||
| 774 | if ($index->getOwnerId() !== '') { |
||
| 781 | |||
| 782 | } |
||
| 783 | |||
| 784 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.