| Conditions | 9 |
| Paths | 17 |
| Total Lines | 51 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 37 | public function process($data, Operation $operation, array $uriVariables = [], array $context = []) |
||
| 38 | { |
||
| 39 | if ($operation instanceof DeleteOperationInterface) { |
||
| 40 | return $this->removeProcessor->process($data, $operation, $uriVariables, $context); |
||
| 41 | } |
||
| 42 | |||
| 43 | if ($operation instanceof Patch && str_contains($operation->getUriTemplate(), 'delete-for-user')) { |
||
| 44 | return $this->processDeleteForUser($data); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** @var Message $message */ |
||
| 48 | $message = $this->persistProcessor->process($data, $operation, $uriVariables, $context); |
||
| 49 | |||
| 50 | foreach ($message->getAttachments() as $attachment) { |
||
| 51 | $attachment->resourceNode->addResourceFile( |
||
| 52 | $attachment->getResourceFileToAttach() |
||
| 53 | ); |
||
| 54 | |||
| 55 | foreach ($message->getReceivers() as $receiver) { |
||
| 56 | $attachment->addUserLink($receiver->getReceiver()); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | $user = $this->security->getUser(); |
||
| 61 | if (!$user) { |
||
| 62 | throw new LogicException('User not found.'); |
||
| 63 | } |
||
| 64 | |||
| 65 | // Check if the relationship already exists |
||
| 66 | $messageRelUserRepository = $this->entityManager->getRepository(MessageRelUser::class); |
||
| 67 | $existingRelation = $messageRelUserRepository->findOneBy([ |
||
| 68 | 'message' => $message, |
||
| 69 | 'receiver' => $user, |
||
| 70 | 'receiverType' => MessageRelUser::TYPE_SENDER, |
||
| 71 | ]); |
||
| 72 | |||
| 73 | if (!$existingRelation) { |
||
| 74 | $messageRelUser = new MessageRelUser(); |
||
| 75 | $messageRelUser->setMessage($message); |
||
| 76 | $messageRelUser->setReceiver($user); |
||
| 77 | $messageRelUser->setReceiverType(MessageRelUser::TYPE_SENDER); |
||
| 78 | $this->entityManager->persist($messageRelUser); |
||
| 79 | } |
||
| 80 | |||
| 81 | if (Message::MESSAGE_TYPE_INBOX === $message->getMsgType()) { |
||
| 82 | $this->saveNotificationForInboxMessage($message); |
||
| 83 | } |
||
| 84 | |||
| 85 | $this->entityManager->flush(); |
||
| 86 | |||
| 87 | return $message; |
||
| 88 | } |
||
| 159 |