| Conditions | 7 |
| Paths | 4 |
| Total Lines | 94 |
| Code Lines | 60 |
| 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 |
||
| 204 | public function changeClientAction(Document $document, Client $client, string $identifier, DocumentType $documentType = null) |
||
| 205 | { |
||
| 206 | if ($documentType instanceof DocumentType) { |
||
| 207 | if ($this->canChangeClient($document)) { |
||
| 208 | |||
| 209 | /** @var Client $currentClient */ |
||
| 210 | $currentClient = $this->clientRepository->findAllByPid($document->getPid())->current(); |
||
| 211 | |||
| 212 | // Move the document to the target client |
||
| 213 | // Fixme: How should the creator be dealt with? |
||
| 214 | // $document->setCreator(); |
||
| 215 | $document->setPid($client->getPid()); |
||
| 216 | $document->setDocumentType($documentType); |
||
| 217 | $documentMapper = $this->objectManager->get(DocumentMapper::class); |
||
| 218 | $documentMapper->setClientPid($client->getPid()); |
||
| 219 | $documentForm = $documentMapper->getDocumentForm($document); |
||
| 220 | $document = $documentMapper->getDocument($documentForm); |
||
| 221 | $internalFormat = new InternalFormat($document->getXmlData(), $client->getPid()); |
||
| 222 | $internalFormat->setDocumentType($documentType->getName()); |
||
| 223 | $document->setXmlData($internalFormat->getXml()); |
||
| 224 | |||
| 225 | if ($client->getOwnerId()) { |
||
| 226 | /** @var ProcessNumberGenerator $processNumberGenerator */ |
||
| 227 | $processNumberGenerator = $this->objectManager->get(ProcessNumberGenerator::class); |
||
| 228 | $processNumber = $processNumberGenerator->getProcessNumber($client->getOwnerId()); |
||
| 229 | $document->setProcessNumber($processNumber); |
||
| 230 | } else { |
||
| 231 | throw new \Exception('Missing client configuration: "owner id"'); |
||
| 232 | } |
||
| 233 | |||
| 234 | $this->documentRepository->update($document); |
||
| 235 | |||
| 236 | // Move files to the target client |
||
| 237 | $files = $document->getFile(); |
||
| 238 | foreach ($files as $file) { |
||
| 239 | $file->setPid($client->getPid()); |
||
| 240 | $this->fileRepository->update($file); |
||
| 241 | } |
||
| 242 | |||
| 243 | // If there are bookmarks, they have to be adjusted, depending on the existence of the related user |
||
| 244 | // inside the target client, and either deleted or moved to the target client. |
||
| 245 | $this->bookmarkRepository->crossClient(true); |
||
| 246 | $bookmarks = $this->bookmarkRepository->findDocumentBookmarks($document); |
||
| 247 | /** @var Bookmark $bookmark */ |
||
| 248 | foreach ($bookmarks as $bookmark) { |
||
| 249 | if ($this->frontendUserRepository->isUserInClient($bookmark->getFeUserUid(), $client->getPid())) { |
||
| 250 | $bookmark->setPid($client->getPid()); |
||
| 251 | $this->bookmarkRepository->update($bookmark); |
||
| 252 | } else { |
||
| 253 | $this->bookmarkRepository->remove($bookmark); |
||
| 254 | } |
||
| 255 | } |
||
| 256 | |||
| 257 | // Move document into the target search index. |
||
| 258 | $elasticSearch = new ElasticSearch($currentClient->getPid()); |
||
| 259 | $elasticSearch->delete($document->getDocumentIdentifier()); |
||
| 260 | $targetElasticSearch = new ElasticSearch($client->getPid()); |
||
| 261 | $targetElasticSearch->index($document); |
||
| 262 | |||
| 263 | $this->flashMessage( |
||
| 264 | 'client_changed', |
||
| 265 | 'client_changed_message', |
||
| 266 | AbstractMessage::OK, |
||
| 267 | [], |
||
| 268 | [$identifier] |
||
| 269 | ); |
||
| 270 | } else { |
||
| 271 | $this->flashMessage( |
||
| 272 | 'change_client_forbidden', |
||
| 273 | 'change_client_forbidden_message', |
||
| 274 | AbstractMessage::ERROR, |
||
| 275 | [], |
||
| 276 | [$identifier] |
||
| 277 | ); |
||
| 278 | } |
||
| 279 | |||
| 280 | $this->view->assign('currentClient', $client); |
||
| 281 | $this->view->assign('document', $document); |
||
| 282 | } else { |
||
| 283 | $this->flashMessage( |
||
| 284 | 'missing_document_type', |
||
| 285 | 'missing_document_type_message', |
||
| 286 | AbstractMessage::ERROR, |
||
| 287 | [], |
||
| 288 | [$identifier] |
||
| 289 | ); |
||
| 290 | |||
| 291 | $this->forward( |
||
| 292 | 'chooseNewClient', |
||
| 293 | null, |
||
| 294 | null, |
||
| 295 | [ |
||
| 296 | 'document' => $document, |
||
| 297 | 'identifier' => $identifier |
||
| 298 | ] |
||
| 356 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.