| Total Complexity | 61 |
| Total Lines | 502 |
| Duplicated Lines | 0 % |
| Changes | 6 | ||
| Bugs | 1 | Features | 0 |
Complex classes like DocumentFormBackofficeController 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.
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 DocumentFormBackofficeController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 31 | class DocumentFormBackofficeController extends AbstractDocumentFormController |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * documentTransferManager |
||
| 35 | * |
||
| 36 | * @var \EWW\Dpf\Services\Transfer\DocumentTransferManager $documentTransferManager |
||
| 37 | */ |
||
| 38 | protected $documentTransferManager; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * fedoraRepository |
||
| 42 | * |
||
| 43 | * @var \EWW\Dpf\Services\Transfer\FedoraRepository $fedoraRepository |
||
| 44 | */ |
||
| 45 | protected $fedoraRepository; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * editingLockService |
||
| 49 | * |
||
| 50 | * @var \EWW\Dpf\Services\Document\EditingLockService |
||
| 51 | * @inject |
||
| 52 | */ |
||
| 53 | protected $editingLockService = null; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * documentManager |
||
| 57 | * |
||
| 58 | * @var \EWW\Dpf\Services\Document\DocumentManager |
||
| 59 | * @inject |
||
| 60 | */ |
||
| 61 | protected $documentManager = null; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * bookmarkRepository |
||
| 65 | * |
||
| 66 | * @var \EWW\Dpf\Domain\Repository\BookmarkRepository |
||
| 67 | * @inject |
||
| 68 | */ |
||
| 69 | protected $bookmarkRepository = null; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * DocumentController constructor. |
||
| 73 | */ |
||
| 74 | public function __construct() |
||
| 75 | { |
||
| 76 | parent::__construct(); |
||
| 77 | |||
| 78 | $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class); |
||
| 79 | $this->documentTransferManager = $objectManager->get(DocumentTransferManager::class); |
||
| 80 | $this->fedoraRepository = $objectManager->get(FedoraRepository::class); |
||
| 81 | $this->documentTransferManager->setRemoteRepository($this->fedoraRepository); |
||
| 82 | } |
||
| 83 | |||
| 84 | public function arrayRecursiveDiff($aArray1, $aArray2) { |
||
| 85 | $aReturn = array(); |
||
| 86 | |||
| 87 | foreach ($aArray1 as $mKey => $mValue) { |
||
| 88 | if (array_key_exists($mKey, $aArray2)) { |
||
| 89 | if (is_array($mValue)) { |
||
| 90 | $aRecursiveDiff = $this->arrayRecursiveDiff($mValue, $aArray2[$mKey]); |
||
| 91 | if (count($aRecursiveDiff)) { $aReturn[$mKey] = $aRecursiveDiff; } |
||
| 92 | } else { |
||
| 93 | if ($mValue != $aArray2[$mKey]) { |
||
| 94 | $aReturn[$mKey] = $mValue; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } else { |
||
| 98 | $aReturn[$mKey] = $mValue; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | return $aReturn; |
||
| 102 | } |
||
| 103 | |||
| 104 | |||
| 105 | /** |
||
| 106 | * action edit |
||
| 107 | * |
||
| 108 | * @param \EWW\Dpf\Domain\Model\DocumentForm $documentForm |
||
| 109 | * @param bool $suggestMod |
||
| 110 | * @param bool activeFileTab |
||
| 111 | * @ignorevalidation $documentForm |
||
| 112 | * @return void |
||
| 113 | */ |
||
| 114 | public function editAction( |
||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @param \EWW\Dpf\Domain\Model\DocumentForm $documentForm |
||
| 162 | * @param bool $restore |
||
| 163 | */ |
||
| 164 | public function createSuggestionDocumentAction(\EWW\Dpf\Domain\Model\DocumentForm $documentForm, $restore = FALSE) |
||
| 165 | { |
||
| 166 | $documentMapper = $this->objectManager->get(DocumentMapper::class); |
||
| 167 | |||
| 168 | $hasFilesFlag = true; |
||
| 169 | |||
| 170 | $workingCopy = $this->documentRepository->findByUid($documentForm->getDocumentUid()); |
||
| 171 | |||
| 172 | if ($workingCopy->isTemporary()) { |
||
| 173 | $workingCopy->setTemporary(false); |
||
| 174 | } |
||
| 175 | |||
| 176 | if (empty($workingCopy->getFileData())) { |
||
| 177 | // no files are linked to the document |
||
| 178 | $hasFilesFlag = false; |
||
| 179 | } |
||
| 180 | |||
| 181 | $newDocument = $this->objectManager->get(Document::class); |
||
| 182 | |||
| 183 | $this->documentRepository->add($newDocument); |
||
| 184 | $this->persistenceManager->persistAll(); |
||
| 185 | |||
| 186 | /* @var $document \EWW\Dpf\Domain\Model\Document */ |
||
| 187 | $document = $documentMapper->getDocument($documentForm); |
||
| 188 | |||
| 189 | /* @var $newDocument \EWW\Dpf\Domain\Model\Document */ |
||
| 190 | $newDocument = $newDocument->copy($document); |
||
| 191 | |||
| 192 | if ($document->getObjectIdentifier()) { |
||
| 193 | $newDocument->setLinkedUid($document->getObjectIdentifier()); |
||
| 194 | } else { |
||
| 195 | $newDocument->setLinkedUid($document->getUid()); |
||
| 196 | } |
||
| 197 | |||
| 198 | $newDocument->setSuggestion(true); |
||
| 199 | $newDocument->setComment($document->getComment()); |
||
| 200 | |||
| 201 | if ($restore) { |
||
| 202 | $newDocument->setTransferStatus("RESTORE"); |
||
| 203 | } |
||
| 204 | |||
| 205 | if (!$hasFilesFlag) { |
||
| 206 | // Add or update files |
||
| 207 | foreach ($documentForm->getNewFiles() as $newFile) { |
||
| 208 | if ($newFile->getUID()) { |
||
| 209 | $this->fileRepository->update($newFile); |
||
| 210 | } else { |
||
| 211 | $newFile->setDocument($newDocument); |
||
| 212 | $this->fileRepository->add($newFile); |
||
| 213 | } |
||
| 214 | |||
| 215 | } |
||
| 216 | } else { |
||
| 217 | // remove files for suggest object |
||
| 218 | $newDocument->setFile($this->objectManager->get(ObjectStorage::class)); |
||
| 219 | } |
||
| 220 | |||
| 221 | |||
| 222 | try { |
||
| 223 | $newDocument->setCreator($this->security->getUser()->getUid()); |
||
| 224 | $this->documentRepository->add($newDocument); |
||
| 225 | $severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::SUCCESS; |
||
| 226 | $this->addFlashMessage("Success", '', $severity,false); |
||
| 227 | } catch (\Throwable $t) { |
||
| 228 | $severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR; |
||
| 229 | $this->addFlashMessage("Failed", '', $severity,false); |
||
| 230 | } |
||
| 231 | |||
| 232 | $this->redirectToDocumentList(); |
||
| 233 | } |
||
| 234 | |||
| 235 | |||
| 236 | public function updateAction(\EWW\Dpf\Domain\Model\DocumentForm $documentForm) |
||
| 259 | ] |
||
| 260 | ); |
||
| 261 | } |
||
| 262 | |||
| 263 | |||
| 264 | /** |
||
| 265 | * @param \EWW\Dpf\Domain\Model\DocumentForm $documentForm |
||
| 266 | * @param string $saveMode |
||
| 267 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 268 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException |
||
| 269 | */ |
||
| 270 | public function updateDocumentAction(\EWW\Dpf\Domain\Model\DocumentForm $documentForm, $saveMode = null) |
||
| 415 | } |
||
| 416 | } |
||
| 417 | |||
| 418 | public function createAction(\EWW\Dpf\Domain\Model\DocumentForm $newDocumentForm) |
||
| 472 | } |
||
| 473 | |||
| 474 | |||
| 475 | /** |
||
| 476 | * action cancel edit |
||
| 477 | * |
||
| 478 | * @param integer $documentUid |
||
| 479 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 480 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException |
||
| 481 | * |
||
| 482 | * @return void |
||
| 483 | */ |
||
| 484 | public function cancelEditAction($documentUid = 0) |
||
| 485 | { |
||
| 486 | if ($documentUid) { |
||
| 487 | /** @var $document \EWW\Dpf\Domain\Model\Document */ |
||
| 488 | $document = $this->documentRepository->findByUid($documentUid); |
||
| 489 | |||
| 490 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
| 491 | } else { |
||
| 492 | $this->redirectToDocumentList(); |
||
| 493 | } |
||
| 494 | } |
||
| 495 | |||
| 496 | /** |
||
| 497 | * action cancel new |
||
| 498 | * |
||
| 499 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 500 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException |
||
| 501 | * |
||
| 502 | * @return void |
||
| 503 | */ |
||
| 504 | public function cancelNewAction() |
||
| 507 | } |
||
| 508 | |||
| 509 | |||
| 510 | public function initializeAction() |
||
| 511 | { |
||
| 512 | $this->authorizationChecker->denyAccessUnlessLoggedIn(); |
||
| 513 | |||
| 514 | parent::initializeAction(); |
||
| 515 | |||
| 516 | } |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Redirect to the current document list. |
||
| 520 | * |
||
| 521 | * @param null $message |
||
| 522 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 523 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException |
||
| 524 | */ |
||
| 525 | protected function redirectToDocumentList($message = null) |
||
| 533 | } |
||
| 534 | } |
||
| 538 |
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