| Conditions | 16 |
| Paths | 47 |
| Total Lines | 53 |
| 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 |
||
| 50 | public function send($notifiable, Notification $notification) |
||
| 51 | { |
||
| 52 | $token = $notifiable->routeNotificationFor('fcm', $notification); |
||
| 53 | |||
| 54 | // Get the message from the notification class |
||
| 55 | $fcmMessage = $notification->toFcm($notifiable); |
||
|
|
|||
| 56 | |||
| 57 | if (! $fcmMessage instanceof Message) { |
||
| 58 | throw CouldNotSendNotification::invalidMessage(); |
||
| 59 | } |
||
| 60 | |||
| 61 | $this->fcmProject = null; |
||
| 62 | if (method_exists($notification, 'fcmProject')) { |
||
| 63 | $this->fcmProject = $notification->fcmProject($notifiable, $fcmMessage); |
||
| 64 | } |
||
| 65 | |||
| 66 | $responses = []; |
||
| 67 | |||
| 68 | try { |
||
| 69 | if (empty($token) && $fcmMessage instanceof FcmMessage) { |
||
| 70 | if ($fcmMessage->getTopic() || $fcmMessage->getCondition()) { |
||
| 71 | $responses[] = $this->sendToFcm($fcmMessage); |
||
| 72 | } |
||
| 73 | } elseif (empty($token) && $fcmMessage instanceof CloudMessage) { |
||
| 74 | if ($fcmMessage->hasTarget()) { |
||
| 75 | $responses[] = $this->sendToFcm($fcmMessage); |
||
| 76 | } |
||
| 77 | } elseif (empty($token)) { |
||
| 78 | $responses = []; |
||
| 79 | } elseif (! is_array($token)) { |
||
| 80 | if ($fcmMessage instanceof CloudMessage) { |
||
| 81 | $fcmMessage = $fcmMessage->withChangedTarget('token', $token); |
||
| 82 | } |
||
| 83 | |||
| 84 | if ($fcmMessage instanceof FcmMessage) { |
||
| 85 | $fcmMessage->setToken($token); |
||
| 86 | } |
||
| 87 | |||
| 88 | $responses[] = $this->sendToFcm($fcmMessage); |
||
| 89 | } else { |
||
| 90 | // Use multicast because there are multiple recipients |
||
| 91 | $partialTokens = array_chunk($token, self::MAX_TOKEN_PER_REQUEST, false); |
||
| 92 | foreach ($partialTokens as $tokens) { |
||
| 93 | $responses[] = $this->sendToFcmMulticast($fcmMessage, $tokens); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } catch (MessagingException $exception) { |
||
| 97 | $this->failedNotification($notifiable, $notification, $exception); |
||
| 98 | throw CouldNotSendNotification::serviceRespondedWithAnError($exception); |
||
| 99 | } |
||
| 100 | |||
| 101 | return $responses; |
||
| 102 | } |
||
| 103 | |||
| 164 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.