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   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 33.33%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 61
ccs 8
cts 24
cp 0.3333
rs 10
c 0
b 0
f 0

2 Methods

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