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   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 67
ccs 0
cts 33
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
B send() 0 28 4
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