Conditions | 7 |
Paths | 21 |
Total Lines | 54 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
64 | public function sendNow(array $recipients, NotificationInterface $notification) |
||
65 | { |
||
66 | // Clone the original notification as will need a copy for each recipient; |
||
67 | $original = clone $notification; |
||
68 | |||
69 | // Set a uuid so notifications from different channels can be grouped. |
||
70 | // Needed when marking as read across all channels. |
||
71 | $uuid = uniqid(); |
||
72 | |||
73 | foreach ($recipients as $notifiable) { |
||
74 | // Get all of the channels the notification would like to be send on. |
||
75 | // Then check each channel against what is configured in the system, |
||
76 | // and which channels the notifiable is subscribed to. |
||
77 | $viaChannels = $notification->getChannels(); |
||
78 | if (empty($viaChannels)) { |
||
79 | $viaChannels = $this->configuredChannels; |
||
80 | } |
||
81 | |||
82 | foreach ($viaChannels as $channel) { |
||
83 | if (!$this->shouldSendNotification($notifiable, $notification, $channel)) { |
||
84 | continue; |
||
85 | } |
||
86 | |||
87 | $currentNotification = clone $original; |
||
88 | $this->formatNotification($notifiable, $currentNotification, $channel, $uuid); |
||
89 | |||
90 | try { |
||
91 | // Dispatch sending event. |
||
92 | $sendingEvent = new NotificationSendingEvent($currentNotification); |
||
93 | $this->eventDispatcher->dispatch(NotificationSendingEvent::NAME, $sendingEvent); |
||
94 | |||
95 | |||
96 | // @TODO: Perhaps send is the only method that should be in the interface |
||
97 | // @TODO: or, use formatthe message and dispatch |
||
98 | // $response = $this->channels[$channel]->send($currentNotification); |
||
|
|||
99 | $message = $this->channels[$channel]->format($currentNotification); |
||
100 | $response = $this->channels[$channel]->dispatch($message); |
||
101 | |||
102 | |||
103 | if ($response) { |
||
104 | // Dispatch sent event. |
||
105 | $successEvent = new NotificationSentEvent($currentNotification); |
||
106 | $this->eventDispatcher->dispatch(NotificationSentEvent::NAME, $successEvent); |
||
107 | } |
||
108 | } catch (\Exception $exception) { |
||
109 | // Dispatch sending failed event. |
||
110 | $successEvent = new NotificationFailedEvent($currentNotification); |
||
111 | $this->eventDispatcher->dispatch(NotificationFailedEvent::NAME, $successEvent); |
||
112 | |||
113 | throw $exception; |
||
114 | } |
||
115 | } |
||
116 | } |
||
117 | } |
||
118 | |||
179 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.