Completed
Push — master ( c0ffdb...42e0ba )
by
unknown
27s queued 12s
created

InterfaxChannel::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace NotificationChannels\Interfax;
4
5
use Illuminate\Notifications\Notification;
6
use Interfax\Client;
7
use NotificationChannels\Interfax\Exceptions\CouldNotSendNotification;
8
9
class InterfaxChannel
10
{
11
    protected $client;
12
13 7
    public function __construct(Client $client)
14
    {
15 7
        $this->client = $client;
16 7
    }
17
18
    /**
19
     * Send the given notification.
20
     *
21
     * @param mixed $notifiable
22
     * @param \Illuminate\Notifications\Notification $notification
23
     *
24
     * @throws \NotificationChannels\Interfax\Exceptions\CouldNotSendNotification
25
     */
26 7
    public function send($notifiable, Notification $notification)
27
    {
28 7
        if (! $faxNumber = $notifiable->routeNotificationFor('interfax')) {
29 1
            return;
30
        }
31
32 6
        $message = $notification->toInterfax($notifiable);
0 ignored issues
show
Bug introduced by
The method toInterfax() 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...
33
34
        try {
35 6
            $fax = $this->client->deliver([
36 6
                'faxNumber' => $faxNumber,
37 6
                'files' => $message->makeFiles(),
38
            ]);
39
40 6
            if ($message->shouldCheckStatus()) {
41 2
                $message->sleep();
42
43 2
                while ($fax->refresh()->status < 0) {
44 1
                    $message->sleep();
45
                }
46
47 2
                if ($fax->refresh()->status > 0) {
48 6
                    throw CouldNotSendNotification::serviceRespondedWithAnError($message, $fax->refresh()->attributes());
49
                }
50
            }
51 1
        } catch (\Interfax\Exception\RequestException $e) {
52
            $exceptionMessage = $e->getMessage().': '.($e->getWrappedException())->getMessage();
53
            throw CouldNotSendNotification::serviceRespondedWithAnError($message, $fax->refresh()->attributes(), $exceptionMessage);
54
        }
55 5
    }
56
}
57