Completed
Push — master ( 678ccb...583462 )
by Abdelrahman
10:00 queued 11s
created

AuthyChannel::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace NotificationChannels\Authy;
6
7
use Illuminate\Notifications\Notification;
8
use Rinvex\Authy\Token as AuthyToken;
9
10
class AuthyChannel
11
{
12
    /**
13
     * The Authy token instance.
14
     *
15
     * @var \Rinvex\Authy\Token
16
     */
17
    protected $authyToken;
18
19
    /**
20
     * Create a new Authy channel instance.
21
     *
22
     * @param \Rinvex\Authy\Token $authyToken
23
     */
24
    public function __construct(AuthyToken $authyToken)
25
    {
26
        $this->authyToken = $authyToken;
27
    }
28
29
    /**
30
     * Send the given notification.
31
     *
32
     * @param mixed                                  $notifiable
33
     * @param \Illuminate\Notifications\Notification $notification
34
     *
35
     * @return bool
36
     */
37
    public function send($notifiable, Notification $notification)
38
    {
39
        if (! $authyId = $notifiable->routeNotificationFor('authy')) {
40
            return false;
41
        }
42
43
        // Prepare notification message
44
        $message = $notification->toAuthy($notifiable);
45
46
        // Send Authy notification and get the result
47
        $result = $this->authyToken->send($authyId, $message->method, $message->force, $message->action, $message->actionMessage);
48
49
        return $result->succeed();
50
    }
51
}
52