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 ( 53051f...8c4fc0 )
by Jhao
01:31
created

SmscRuApi::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 0
cts 10
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 3
crap 2
1
<?php
2
3
namespace NotificationChannels\SmscRu;
4
5
use DomainException;
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 string */
14
    protected $apiUrl = 'https://smsc.ru/sys/send.php';
15
16
    /** @var HttpClient */
17
    protected $httpClient;
18
19
    /** @var string */
20
    protected $login;
21
22
    /** @var string */
23
    protected $secret;
24
25
    /** @var string */
26
    protected $sender;
27
28
    public function __construct($login, $secret, $sender)
29
    {
30
        $this->login = $login;
31
        $this->secret = $secret;
32
        $this->sender = $sender;
33
34
        $this->httpClient = new HttpClient([
35
            'timeout' => 5,
36
            'connect_timeout' => 5,
37
        ]);
38
    }
39
40
    /**
41
     * @param  array  $params
42
     *
43
     * @return array
44
     *
45
     * @throws CouldNotSendNotification
46
     */
47
    public function send($params)
48
    {
49
        $base = [
50
            'charset' => 'utf-8',
51
            'login'   => $this->login,
52
            'psw'     => $this->secret,
53
            'sender'  => $this->sender,
54
            'fmt'     => self::FORMAT_JSON,
55
        ];
56
57
        $params = array_merge($base, $params);
58
59
        try {
60
            $response = $this->httpClient->post($this->apiUrl, ['form_params' => $params]);
61
62
            $response = json_decode((string) $response->getBody(), true);
63
64
            if (isset($response['error'])) {
65
                throw new DomainException($response['error'], $response['error_code']);
66
            }
67
68
            return $response;
69
        } catch (DomainException $exception) {
70
            throw CouldNotSendNotification::smscRespondedWithAnError($exception);
71
        } catch (\Exception $exception) {
72
            throw CouldNotSendNotification::couldNotCommunicateWithSmsc($exception);
73
        }
74
    }
75
}
76