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
Pull Request — master (#18)
by
unknown
02:15 queued 58s
created

SmscRuApi   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 44.44%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 68
ccs 12
cts 27
cp 0.4444
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 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 HttpClient */
14
    protected $httpClient;
15
16
    /** @var string */
17
    protected $url;
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($config)
29
    {
30 2
        $this->url = array_get($config, 'host', 'https://smsc.ru/') . 'sys/send.php';
31 2
        $this->login = array_get($config, 'login');
32 2
        $this->secret = array_get($config, 'secret');
33 2
        $this->sender = array_get($config, 'sender');
34
35 2
        $this->httpClient = new HttpClient([
36 2
            'timeout' => 5,
37 2
            'connect_timeout' => 5,
38 2
        ]);
39 2
    }
40
41
    /**
42
     * @param  array  $params
43
     *
44
     * @return array
45
     *
46
     * @throws CouldNotSendNotification
47
     */
48 1
    public function send($params)
49
    {
50
        $base = [
51
            'charset' => 'utf-8',
52
            'login'   => $this->login,
53
            'psw'     => $this->secret,
54
            'sender'  => $this->sender,
55
            'fmt'     => self::FORMAT_JSON,
56
        ];
57
58
        $params = array_merge($params, $base);
59
60
        try {
61
            $response = $this->httpClient->post($this->url, ['form_params' => $params]);
62
63
            $response = json_decode((string) $response->getBody(), true);
64
65 1
            if (isset($response['error'])) {
66
                throw new DomainException($response['error'], $response['error_code']);
67
            }
68
69
            return $response;
70
        } catch (DomainException $exception) {
71
            throw CouldNotSendNotification::smscRespondedWithAnError($exception);
72
        } catch (\Exception $exception) {
73
            throw CouldNotSendNotification::couldNotCommunicateWithSmsc($exception);
74
        }
75
    }
76
}
77