| Conditions | 10 |
| Paths | 12 |
| Total Lines | 44 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 36 | public function process($data, Operation $operation, array $uriVariables = [], array $context = []) |
||
| 37 | { |
||
| 38 | if ($operation instanceof DeleteOperationInterface) { |
||
| 39 | return $this->removeProcessor->process($data, $operation, $uriVariables, $context); |
||
| 40 | } |
||
| 41 | |||
| 42 | if ($operation instanceof Patch && str_contains($operation->getUriTemplate(), 'delete-for-user')) { |
||
| 43 | return $this->processDeleteForUser($data); |
||
| 44 | } |
||
| 45 | |||
| 46 | if ($operation instanceof Patch && str_contains($operation->getUriTemplate(), 'check-and-update-status')) { |
||
| 47 | return $this->checkAndUpdateMessageStatus($data); |
||
| 48 | } |
||
| 49 | |||
| 50 | /** @var Message $message */ |
||
| 51 | $message = $this->persistProcessor->process($data, $operation, $uriVariables, $context); |
||
| 52 | |||
| 53 | foreach ($message->getAttachments() as $attachment) { |
||
| 54 | $attachment->resourceNode->addResourceFile( |
||
| 55 | $attachment->getResourceFileToAttach() |
||
| 56 | ); |
||
| 57 | |||
| 58 | foreach ($message->getReceivers() as $receiver) { |
||
| 59 | $attachment->addUserLink($receiver->getReceiver()); |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | $user = $this->security->getUser(); |
||
| 64 | if (!$user) { |
||
| 65 | throw new \LogicException('User not found.'); |
||
| 66 | } |
||
| 67 | $messageRelUser = new MessageRelUser(); |
||
| 68 | $messageRelUser->setMessage($message); |
||
| 69 | $messageRelUser->setReceiver($user); |
||
| 70 | $messageRelUser->setReceiverType(MessageRelUser::TYPE_SENDER); |
||
| 71 | $this->entityManager->persist($messageRelUser); |
||
| 72 | |||
| 73 | if ($message->getMsgType() === Message::MESSAGE_TYPE_INBOX) { |
||
| 74 | $this->saveNotificationForInboxMessage($message); |
||
| 75 | } |
||
| 76 | |||
| 77 | $this->entityManager->flush(); |
||
| 78 | |||
| 79 | return $message; |
||
| 80 | } |
||
| 167 |