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 ( 3dd017...b8ade9 )
by Jhao
02:54
created

SmscRuApi::send()   B

Complexity

Conditions 4
Paths 7

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 14.993

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 2
cts 17
cp 0.1176
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 18
nc 7
nop 1
crap 14.993
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 3
    public function __construct($login, $secret, $sender)
29
    {
30 3
        $this->login = $login;
31 3
        $this->secret = $secret;
32 3
        $this->sender = $sender;
33
34 3
        $this->httpClient = new HttpClient([
35 3
            'timeout' => 5,
36 3
            'connect_timeout' => 5,
37 3
        ]);
38 3
    }
39
40
    /**
41
     * @param  array  $params
42
     *
43
     * @return array
44
     *
45
     * @throws CouldNotSendNotification
46
     */
47 1
    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($params, $base);
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 1
                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