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.

GoSmsApi   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 88
ccs 0
cts 35
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 1
A send() 0 24 4
1
<?php
2
3
namespace NotificationChannels\GoSms;
4
5
use DomainException;
6
use GuzzleHttp\Client as HttpClient;
7
use NotificationChannels\GoSms\Exceptions\CouldNotSendNotification;
8
9
class GoSmsApi
10
{
11
    const FORMAT_JSON = 3;
12
13
    /** @var string */
14
    protected $apiUrl = 'http://api.gosms.com.my/eapi/sms.aspx';
15
16
    /** @var HttpClient */
17
    protected $httpClient;
18
19
    /** @var string */
20
    protected $company;
21
22
    /** @var string */
23
    protected $username;
24
25
    /** @var string */
26
    protected $password;
27
28
    /** @var string */
29
    protected $sender;
30
31
    /** @var string */
32
    protected $gateway;
33
34
    /** @var string */
35
    protected $type;
36
37
    /** @var string */
38
    protected $charge;
39
40
    /** @var string */
41
    protected $maskid;
42
43
    /** @var string */
44
    protected $convert;
45
46
    public function __construct($config)
47
    {
48
        $this->company = $config['company'];
49
        $this->username = $config['username'];
50
        $this->password = $config['password'];
51
        $this->sender = $config['sender'];
52
        $this->gateway = $config['gateway'];
53
        $this->mode = $config['mode'];
0 ignored issues
show
Bug introduced by
The property mode does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
54
        $this->type = $config['type'];
55
        $this->charge = $config['charge'];
56
        $this->maskid = $config['maskid'];
57
        $this->convert = $config['convert'];
58
59
        $this->httpClient = new HttpClient([
60
            'base_uri' =>  $this->apiUrl,
61
            'timeout' => 2.0,
62
        ]);
63
    }
64
65
    /**
66
     * @param  array  $params
67
     *
68
     * @return array
69
     *
70
     * @throws CouldNotSendNotification
71
     */
72
    public function send($params)
73
    {
74
        try {
75
            $sendsms_url = "?company={$this->company}&user={$this->username}&password={$this->password}&gateway={$this->gateway}&mode={$this->mode}&type={$this->type}&hp={$params['hp']}&mesg={$params['mesg']}&charge={$this->charge}&maskid={$this->maskid}&convert={$this->convert}";
76
77
            $response = $this->httpClient->request('GET', $this->apiUrl.$sendsms_url);
78
79
            $stream = $response->getBody();
80
81
            $content = $stream->getContents();
82
83
            $response = json_decode((string) $response->getBody(), true);
84
85
            if ($content == 'E01') {
86
                throw new \Exception('E01');
87
            }
88
89
            return $response;
90
        } catch (DomainException $exception) {
91
            throw CouldNotSendNotification::exceptionGoSmsRespondedWithAnError($exception);
92
        } catch (\Exception $exception) {
93
            throw CouldNotSendNotification::couldNotCommunicateWithGoSms($exception);
94
        }
95
    }
96
}
97