| Conditions | 18 |
| Paths | 46 |
| Total Lines | 88 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 124 | public function update(Document $document, $workflowTransition = null, $deletedFiles = [], $newFiles = []) |
||
| 125 | { |
||
| 126 | // xml data fields are limited to 64 KB |
||
| 127 | if (strlen($document->getXmlData()) >= 64 * 1024 || strlen($document->getSlubInfoData() >= 64 * 1024)) { |
||
| 128 | throw new \EWW\Dpf\Exceptions\DocumentMaxSizeErrorException("Maximum document size exceeded."); |
||
| 129 | } |
||
| 130 | |||
| 131 | /** @var \Symfony\Component\Workflow\Workflow $workflow */ |
||
| 132 | $workflow = $this->objectManager->get(DocumentWorkflow::class)->getWorkflow(); |
||
| 133 | |||
| 134 | if ($workflowTransition) { |
||
| 135 | if (!$workflow->can($document, $workflowTransition)) { |
||
| 136 | return false; |
||
| 137 | } |
||
| 138 | $workflow->apply($document, $workflowTransition); |
||
| 139 | } |
||
| 140 | |||
| 141 | if ($document->isSuggestion()) { |
||
| 142 | |||
| 143 | // if local suggestion copy |
||
| 144 | $updateResult = false; |
||
| 145 | |||
| 146 | } elseif ($document->isTemporaryCopy()) { |
||
| 147 | |||
| 148 | // if temporary working copy |
||
| 149 | $updateResult = $this->updateRemotely($document, $workflowTransition, $deletedFiles, $newFiles); |
||
| 150 | |||
| 151 | } elseif ( |
||
| 152 | $document->isWorkingCopy() && |
||
| 153 | ( |
||
| 154 | $workflowTransition === DocumentWorkflow::TRANSITION_POSTPONE || |
||
| 155 | $workflowTransition === DocumentWorkflow::TRANSITION_DISCARD || |
||
| 156 | $workflowTransition === DocumentWorkflow::TRANSITION_RELEASE_ACTIVATE |
||
| 157 | ) |
||
| 158 | ) { |
||
| 159 | |||
| 160 | // if local working copy with state change |
||
| 161 | $updateResult = $this->updateRemotely($document, $workflowTransition, $deletedFiles, $newFiles); |
||
| 162 | |||
| 163 | } elseif ($document->isWorkingCopy()) { |
||
| 164 | |||
| 165 | // if local working copy with no state change |
||
| 166 | $this->updateFiles($document, $deletedFiles, $newFiles); |
||
| 167 | $this->documentRepository->update($document); |
||
| 168 | $updateResult = $document->getDocumentIdentifier(); |
||
| 169 | |||
| 170 | } elseif ($workflowTransition == DocumentWorkflow::TRANSITION_RELEASE_PUBLISH) { |
||
| 171 | // Fedora ingest |
||
| 172 | if ($ingestedDocument = $this->getDocumentTransferManager()->ingest($document)) { |
||
| 173 | |||
| 174 | // After ingest all related bookmarks need an update of the identifier into an fedora object identifier. |
||
| 175 | if ($ingestedDocument instanceof Document) { |
||
| 176 | /** @var Bookmark $bookmark */ |
||
| 177 | foreach ($this->bookmarkRepository->findByDocumentIdentifier($ingestedDocument->getUid()) as $bookmark) { |
||
| 178 | $bookmark->setDocumentIdentifier($ingestedDocument->getDocumentIdentifier()); |
||
| 179 | $this->bookmarkRepository->update($bookmark); |
||
| 180 | } |
||
| 181 | } else { |
||
| 182 | throw \Exception("Logical exception while updating bookmarks."); |
||
| 183 | } |
||
| 184 | |||
| 185 | $this->removeDocument($document); |
||
| 186 | $updateResult = $document->getDocumentIdentifier(); |
||
| 187 | } else { |
||
| 188 | $updateResult = false; |
||
| 189 | } |
||
| 190 | } else { |
||
| 191 | |||
| 192 | $this->updateFiles($document, $deletedFiles, $newFiles); |
||
| 193 | $this->documentRepository->update($document); |
||
| 194 | $updateResult = $document->getDocumentIdentifier(); |
||
| 195 | } |
||
| 196 | |||
| 197 | if ($updateResult) { |
||
| 198 | |||
| 199 | if (DocumentWorkflow::TRANSITION_RELEASE_PUBLISH) { |
||
| 200 | // delete local document from index |
||
| 201 | $this->signalSlotDispatcher->dispatch( |
||
| 202 | AbstractController::class, 'deleteDocumentFromIndex', [$document->getUid()] |
||
| 203 | ); |
||
| 204 | } |
||
| 205 | // index the document |
||
| 206 | $this->signalSlotDispatcher->dispatch( |
||
| 207 | AbstractController::class, 'indexDocument', [$document] |
||
| 208 | ); |
||
| 209 | } |
||
| 210 | |||
| 211 | return $updateResult; |
||
| 212 | } |
||
| 333 |