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.

SmscRuApi::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace NotificationChannels\SmscRu;
4
5
use GuzzleHttp\Client as HttpClient;
6
use Illuminate\Support\Arr;
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