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 ( 186cdf...3756b6 )
by Jhao
03:11
created

SmscRuApi   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 36%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 66
ccs 9
cts 25
cp 0.36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 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
    public 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
    /** @var array */
29
    protected $extra;
30
31 2
    public function __construct(array $config)
32
    {
33 2
        $this->login = Arr::get($config, 'login');
34 2
        $this->secret = Arr::get($config, 'secret');
35 2
        $this->sender = Arr::get($config, 'sender');
36 2
        $this->endpoint = Arr::get($config, 'host', 'https://smsc.ru/').'sys/send.php';
37
38 2
        $this->extra = Arr::get($config, 'extra', []);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Illuminate\Support\Arr:...nfig, 'extra', array()) of type * is incompatible with the declared type array of property $extra.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
39
40 2
        $this->client = new HttpClient([
41 2
            'timeout' => 5,
42
            'connect_timeout' => 5,
43
        ]);
44 2
    }
45
46
    public function send($params)
47
    {
48
        $base = [
49
            'charset' => 'utf-8',
50
            'login'   => $this->login,
51
            'psw'     => $this->secret,
52
            'sender'  => $this->sender,
53
            'fmt'     => self::FORMAT_JSON,
54
        ];
55
56
        $params = \array_merge($base, \array_filter($params), $this->extra);
57
58
        try {
59
            $response = $this->client->request('POST', $this->endpoint, ['form_params' => $params]);
60
61
            $response = \json_decode((string) $response->getBody(), true);
62
63
            if (isset($response['error'])) {
64
                throw new \DomainException($response['error'], $response['error_code']);
65
            }
66
67
            return $response;
68
        } catch (\DomainException $exception) {
69
            throw CouldNotSendNotification::smscRespondedWithAnError($exception);
70
        } catch (\Exception $exception) {
71
            throw CouldNotSendNotification::couldNotCommunicateWithSmsc($exception);
72
        }
73
    }
74
}
75