Conditions | 10 |
Paths | 19 |
Total Lines | 49 |
Code Lines | 28 |
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 namespace nyx\notify\transports; |
||
124 | public function send(interfaces\Notifiable $notifiable, interfaces\Notification $notification) |
||
125 | { |
||
126 | /* @var slack\interfaces\Slackable $notification */ |
||
127 | if (!$this->supports($notification)) { |
||
|
|||
128 | throw new \InvalidArgumentException('The given Notification is not supported (did you forget to implement the Slackable Interface?).'); |
||
129 | } |
||
130 | |||
131 | if (false === $notifiable->routeNotification('slack', $message = $notification->toSlack($notifiable))) { |
||
132 | return; |
||
133 | } |
||
134 | |||
135 | // Note: The dual 'to()' cast is intended - toSlack() above will let the Notification build the appropriate |
||
136 | // Message while the latter toArray() call flattens the whole structure down into an array that we can more |
||
137 | // easily digest and pass on to Slack itself. |
||
138 | $message = $message->toArray(); |
||
139 | |||
140 | // We need text or an attachment for the message to actually be displayed in Slack. |
||
141 | if (empty($message['text']) && empty($message['attachments'])) { |
||
142 | throw new \RuntimeException('A message to Slack must contain at least either text or an attachment, got neither.'); |
||
143 | } |
||
144 | |||
145 | // Apply our defaults where the Message doesn't override them. |
||
146 | $message['token'] = $message['token'] ?? $this->token; |
||
147 | $message['endpoint'] = $message['endpoint'] ?? $this->endpoint; |
||
148 | $message['username'] = $message['username'] ?? $this->username; |
||
149 | $message['parse'] = $message['parse'] ?? $this->parse; |
||
150 | $message['link_names'] = $this->linkNames ? 1 : 0; |
||
151 | $message['unfurl_links'] = $this->unfurlLinks; |
||
152 | $message['unfurl_media'] = $this->unfurlMedia; |
||
153 | $message['mrkdwn'] = $this->allowMarkdown; |
||
154 | $message['mrkdwn_in'] = $this->markdownInAttachments; |
||
155 | |||
156 | // We're applying the icon separately since we need to know what key it's going to be sent as. |
||
157 | $icon = $message['icon'] ?? $this->icon; |
||
158 | |||
159 | if ($icon) { |
||
160 | $message[static::determineIconType($icon)] = $icon; |
||
161 | } |
||
162 | |||
163 | if (isset($message['response_url'])) { |
||
164 | $this->sendResponse($message); |
||
165 | } elseif ($message['token']) { |
||
166 | $this->sendApiMessage($message); |
||
167 | } elseif ($message['endpoint']) { |
||
168 | $this->sendWebhookMessage($message); |
||
169 | } else { |
||
170 | throw new \InvalidArgumentException('No oAuth token nor webhook endpoint given, could not send the Notification.'); |
||
171 | } |
||
172 | } |
||
173 | |||
227 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: