Conditions | 9 |
Paths | 13 |
Total Lines | 65 |
Code Lines | 42 |
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 |
||
51 | public function handle(Event $event): void { |
||
52 | if ($event instanceof AddressBookCreatedEvent) { |
||
53 | try { |
||
54 | $this->activityBackend->onAddressbookCreate( |
||
55 | $event->getAddressBookData() |
||
56 | ); |
||
57 | |||
58 | $this->logger->debug( |
||
59 | sprintf('Activity generated for new addressbook %d', $event->getAddressBookId()) |
||
60 | ); |
||
61 | } catch (Throwable $e) { |
||
62 | // Any error with activities shouldn't abort the addressbook creation, so we just log it |
||
63 | $this->logger->error('Error generating activities for a new addressbook: ' . $e->getMessage(), [ |
||
64 | 'exception' => $e, |
||
65 | ]); |
||
66 | } |
||
67 | } elseif ($event instanceof AddressBookUpdatedEvent) { |
||
68 | try { |
||
69 | $this->activityBackend->onAddressbookUpdate( |
||
70 | $event->getAddressBookData(), |
||
71 | $event->getShares(), |
||
72 | $event->getMutations() |
||
73 | ); |
||
74 | |||
75 | $this->logger->debug( |
||
76 | sprintf('Activity generated for changed addressbook %d', $event->getAddressBookId()) |
||
77 | ); |
||
78 | } catch (Throwable $e) { |
||
79 | // Any error with activities shouldn't abort the addressbook update, so we just log it |
||
80 | $this->logger->error('Error generating activities for a changed addressbook: ' . $e->getMessage(), [ |
||
81 | 'exception' => $e, |
||
82 | ]); |
||
83 | } |
||
84 | } elseif ($event instanceof AddressBookDeletedEvent) { |
||
85 | try { |
||
86 | $this->activityBackend->onAddressbookDelete( |
||
87 | $event->getAddressBookData(), |
||
88 | $event->getShares() |
||
89 | ); |
||
90 | |||
91 | $this->logger->debug( |
||
92 | sprintf('Activity generated for deleted addressbook %d', $event->getAddressBookId()) |
||
93 | ); |
||
94 | } catch (Throwable $e) { |
||
95 | // Any error with activities shouldn't abort the addressbook deletion, so we just log it |
||
96 | $this->logger->error('Error generating activities for a deleted addressbook: ' . $e->getMessage(), [ |
||
97 | 'exception' => $e, |
||
98 | ]); |
||
99 | } |
||
100 | } elseif ($event instanceof AddressBookShareUpdatedEvent) { |
||
101 | try { |
||
102 | $this->activityBackend->onAddressbookUpdateShares( |
||
103 | $event->getAddressBookData(), |
||
104 | $event->getOldShares(), |
||
105 | $event->getAdded(), |
||
106 | $event->getRemoved() |
||
107 | ); |
||
108 | |||
109 | $this->logger->debug( |
||
110 | sprintf('Activity generated for (un)sharing addressbook %d', $event->getAddressBookId()) |
||
111 | ); |
||
112 | } catch (Throwable $e) { |
||
113 | // Any error with activities shouldn't abort the addressbook creation, so we just log it |
||
114 | $this->logger->error('Error generating activities for (un)sharing addressbook: ' . $e->getMessage(), [ |
||
115 | 'exception' => $e, |
||
116 | ]); |
||
121 |