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.
Completed
Push — master ( 977b4e...210f22 )
by Jhao
06:32 queued 05:34
created

SmscRuApi::send()   A

Complexity

Conditions 4
Paths 7

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 0
cts 16
cp 0
rs 9.472
c 0
b 0
f 0
cc 4
nc 7
nop 1
crap 20
1
<?php
2
3
namespace NotificationChannels\SmscRu;
4
5
use Illuminate\Support\Arr;
6
use GuzzleHttp\Client as HttpClient;
7
use NotificationChannels\SmscRu\Exceptions\CouldNotSendNotification;
8
9
class SmscRuApi
10
{
11
    const FORMAT_JSON = 3;
12
13
    /** @var HttpClient */
14
    protected $client;
15
16
    /** @var string */
17
    protected $endpoint;
18
19
    /** @var string */
20
    protected $login;
21
22
    /** @var string */
23
    protected $secret;
24
25
    /** @var string */
26
    protected $sender;
27
28 2
    public function __construct(array $config)
29
    {
30 2
        $this->login = Arr::get($config, 'login');
31 2
        $this->secret = Arr::get($config, 'secret');
32 2
        $this->sender = Arr::get($config, 'sender');
33 2
        $this->endpoint = Arr::get($config, 'host', 'https://smsc.ru/').'sys/send.php';
34
35 2
        $this->client = new HttpClient([
36 2
            'timeout' => 5,
37
            'connect_timeout' => 5,
38
        ]);
39 2
    }
40
41
    public function send($params)
42
    {
43
        $base = [
44
            'charset' => 'utf-8',
45
            'login'   => $this->login,
46
            'psw'     => $this->secret,
47
            'sender'  => $this->sender,
48
            'fmt'     => self::FORMAT_JSON,
49
        ];
50
51
        $params = \array_merge($base, \array_filter($params));
52
53
        try {
54
            $response = $this->client->request('POST', $this->endpoint, ['form_params' => $params]);
55
56
            $response = \json_decode((string) $response->getBody(), true);
57
58
            if (isset($response['error'])) {
59
                throw new \DomainException($response['error'], $response['error_code']);
60
            }
61
62
            return $response;
63
        } catch (\DomainException $exception) {
64
            throw CouldNotSendNotification::smscRespondedWithAnError($exception);
65
        } catch (\Exception $exception) {
66
            throw CouldNotSendNotification::couldNotCommunicateWithSmsc($exception);
67
        }
68
    }
69
}
70