GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TelerivetChannel::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace CoreProc\NotificationChannels\Telerivet;
4
5
use CoreProc\NotificationChannels\Telerivet\Exceptions\CouldNotSendNotification;
6
use GuzzleHttp\Client;
7
use GuzzleHttp\Exception\RequestException;
8
use Illuminate\Notifications\Notification;
9
use Psr\Http\Message\ResponseInterface;
10
11
class TelerivetChannel
12
{
13
    public const DEFAULT_API_URL = 'https://api.telerivet.com';
14
15
    protected $client;
16
17
    public function __construct(Client $client)
18
    {
19
        $this->client = $client;
20
    }
21
22
    /**
23
     * Send the given notification.
24
     *
25
     * @param mixed $notifiable
26
     * @param Notification $notification
27
     *
28
     * @return ResponseInterface
29
     * @throws CouldNotSendNotification
30
     */
31
    public function send($notifiable, Notification $notification)
32
    {
33
        $telerivetMessage = $notification->toTelerivet($notifiable);
0 ignored issues
show
Bug introduced by
The method toTelerivet() 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...
34
35
        // If the message does not have a to_number of contact_id
36
        if (empty($telerivetMessage->getToNumber()) && empty($telerivetMessage->getContactId())) {
37
            // Check first if the notifiable object has a telerivetContactId
38
            if (! empty($notifiable->routeNotificationFor('telerivetContactId'))) {
39
                $telerivetMessage->setContactId($notifiable->routeNotificationFor('telerivetContactId'));
40
            } else {
41
                // If not, default to the "telerivet" route which should be a phone number
42
                $telerivetMessage->setToNumber($notifiable->routeNotificationFor('telerivet'));
43
            }
44
        }
45
46
        try {
47
            $response = $this->client->post(
48
                'v1/projects/' . config('broadcasting.connections.telerivet.project_id') . '/messages/send',
49
                [
50
                    'auth' => [config('broadcasting.connections.telerivet.api_key'), ''],
51
                    'json' => $telerivetMessage->toArray(),
52
                ]
53
            );
54
        } catch (RequestException $requestException) {
55
            throw CouldNotSendNotification::serviceRespondedWithAnError($requestException);
56
        }
57
58
        return $response;
59
    }
60
}
61