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