| Conditions | 7 |
| Paths | 10 |
| Total Lines | 53 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 51 | public function handle(Event $event): void { |
||
| 52 | if ($event instanceof CardCreatedEvent) { |
||
| 53 | try { |
||
| 54 | $this->activityBackend->triggerCardActivity( |
||
| 55 | Card::SUBJECT_ADD, |
||
| 56 | $event->getAddressBookData(), |
||
| 57 | $event->getShares(), |
||
| 58 | $event->getCardData() |
||
| 59 | ); |
||
| 60 | |||
| 61 | $this->logger->debug( |
||
| 62 | sprintf('Activity generated for a new card in addressbook %d', $event->getAddressBookId()) |
||
| 63 | ); |
||
| 64 | } catch (Throwable $e) { |
||
| 65 | // Any error with activities shouldn't abort the addressbook creation, so we just log it |
||
| 66 | $this->logger->error('Error generating activities for a new card in addressbook: ' . $e->getMessage(), [ |
||
| 67 | 'exception' => $e, |
||
| 68 | ]); |
||
| 69 | } |
||
| 70 | } elseif ($event instanceof CardUpdatedEvent) { |
||
| 71 | try { |
||
| 72 | $this->activityBackend->triggerCardActivity( |
||
| 73 | Card::SUBJECT_UPDATE, |
||
| 74 | $event->getAddressBookData(), |
||
| 75 | $event->getShares(), |
||
| 76 | $event->getCardData() |
||
| 77 | ); |
||
| 78 | |||
| 79 | $this->logger->debug( |
||
| 80 | sprintf('Activity generated for a changed card in addressbook %d', $event->getAddressBookId()) |
||
| 81 | ); |
||
| 82 | } catch (Throwable $e) { |
||
| 83 | // Any error with activities shouldn't abort the addressbook update, so we just log it |
||
| 84 | $this->logger->error('Error generating activities for a changed card in addressbook: ' . $e->getMessage(), [ |
||
| 85 | 'exception' => $e, |
||
| 86 | ]); |
||
| 87 | } |
||
| 88 | } elseif ($event instanceof CardDeletedEvent) { |
||
| 89 | try { |
||
| 90 | $this->activityBackend->triggerCardActivity( |
||
| 91 | Card::SUBJECT_DELETE, |
||
| 92 | $event->getAddressBookData(), |
||
| 93 | $event->getShares(), |
||
| 94 | $event->getCardData() |
||
| 95 | ); |
||
| 96 | |||
| 97 | $this->logger->debug( |
||
| 98 | sprintf('Activity generated for a deleted card in addressbook %d', $event->getAddressBookId()) |
||
| 99 | ); |
||
| 100 | } catch (Throwable $e) { |
||
| 101 | // Any error with activities shouldn't abort the addressbook deletion, so we just log it |
||
| 102 | $this->logger->error('Error generating activities for a deleted card in addressbook: ' . $e->getMessage(), [ |
||
| 103 | 'exception' => $e, |
||
| 104 | ]); |
||
| 109 |