| Conditions | 12 |
| Paths | 44 |
| Total Lines | 61 |
| Code Lines | 43 |
| 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 |
||
| 77 | public function handle(Event $event): void { |
||
| 78 | if (!($event instanceof ContactInteractedWithEvent)) { |
||
| 79 | return; |
||
| 80 | } |
||
| 81 | |||
| 82 | if ($event->getUid() === null && $event->getEmail() === null && $event->getFederatedCloudId() === null) { |
||
| 83 | $this->logger->warning("Contact interaction event has no user identifier set"); |
||
| 84 | return; |
||
| 85 | } |
||
| 86 | |||
| 87 | $existing = $this->mapper->findMatch( |
||
| 88 | $event->getActor(), |
||
| 89 | $event->getUid(), |
||
| 90 | $event->getEmail(), |
||
| 91 | $event->getFederatedCloudId() |
||
| 92 | ); |
||
| 93 | if (!empty($existing)) { |
||
| 94 | $now = $this->timeFactory->getTime(); |
||
| 95 | foreach ($existing as $c) { |
||
| 96 | $c->setLastContact($now); |
||
| 97 | $this->mapper->update($c); |
||
| 98 | } |
||
| 99 | |||
| 100 | return; |
||
| 101 | } |
||
| 102 | |||
| 103 | $contact = new RecentContact(); |
||
| 104 | $contact->setActorUid($event->getActor()->getUID()); |
||
| 105 | if ($event->getUid() !== null) { |
||
| 106 | $contact->setUid($event->getUid()); |
||
| 107 | } |
||
| 108 | if ($event->getEmail() !== null) { |
||
| 109 | $contact->setEmail($event->getEmail()); |
||
| 110 | } |
||
| 111 | if ($event->getFederatedCloudId() !== null) { |
||
| 112 | $contact->setFederatedCloudId($event->getFederatedCloudId()); |
||
| 113 | } |
||
| 114 | $contact->setLastContact($this->timeFactory->getTime()); |
||
| 115 | |||
| 116 | $copy = $this->cardSearchDao->findExisting( |
||
|
|
|||
| 117 | $event->getActor(), |
||
| 118 | $event->getUid(), |
||
| 119 | $event->getEmail(), |
||
| 120 | $event->getFederatedCloudId() |
||
| 121 | ); |
||
| 122 | if ($copy !== null) { |
||
| 123 | try { |
||
| 124 | $parsed = Reader::read($copy, Reader::OPTION_FORGIVING); |
||
| 125 | $parsed->CATEGORIES = $this->l10n->t('Recently contacted'); |
||
| 126 | $contact->setCard($parsed->serialize()); |
||
| 127 | } catch (Throwable $e) { |
||
| 128 | $this->logger->logException($e, [ |
||
| 129 | 'message' => 'Could not parse card to add recent category: ' . $e->getMessage(), |
||
| 130 | 'level' => ILogger::WARN, |
||
| 131 | ]); |
||
| 132 | $contact->setCard($copy); |
||
| 133 | } |
||
| 134 | } else { |
||
| 135 | $contact->setCard($this->generateCard($contact)); |
||
| 136 | } |
||
| 137 | $this->mapper->insert($contact); |
||
| 138 | } |
||
| 172 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.