MicrosoftTeamsChannel::send()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace NotificationChannels\MicrosoftTeams;
4
5
use Illuminate\Notifications\Notification;
6
7
class MicrosoftTeamsChannel
8
{
9
    /**
10
     * @var MicrosoftTeams
11
     */
12
    protected $microsoftTeams;
13
14
    /**
15
     * Channel constructor.
16
     *
17
     * @param MicrosoftTeams $microsoftTeams
18
     */
19 3
    public function __construct(MicrosoftTeams $microsoftTeams)
20
    {
21 3
        $this->microsoftTeams = $microsoftTeams;
22 3
    }
23
24
    /**
25
     * Send the given notification.
26
     *
27
     * @param mixed $notifiable
28
     * @param Notification $notification
29
     *
30
     * @return \Psr\Http\Message\ResponseInterface|null
31
     */
32 3
    public function send($notifiable, Notification $notification)
33
    {
34 3
        $message = $notification->toMicrosoftTeams($notifiable);
0 ignored issues
show
Bug introduced by
The method toMicrosoftTeams() does not seem to exist on object<Illuminate\Notifications\Notification>.

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.

Loading history...
35
36
        // if the recipient is not defined get it from the notifiable object
37 3
        if ($message->toNotGiven()) {
38 2
            $to = $notifiable->routeNotificationFor('microsoftTeams');
39
40 2
            $message->to($to);
41
        }
42
43 2
        $response = $this->microsoftTeams->send($message->getWebhookUrl(), $message->toArray());
44
45 2
        return $response;
46
    }
47
}
48