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 ( 515e74...726d62 )
by Shiro
09:28
created

GoSmsApi   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
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 67
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
B 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
    public function __construct($company, $username, $password, $sender)
32
    {
33
        $this->company = $company;
34
        $this->username = $username;
35
        $this->password = $password;
36
        $this->sender = $sender;
37
38
        $this->httpClient = new HttpClient([
39
            'base_uri' =>  $this->apiUrl,
40
            'timeout' => 2.0,
41
        ]);
42
    }
43
44
    /**
45
     * @param  array  $params
46
     *
47
     * @return array
48
     *
49
     * @throws CouldNotSendNotification
50
     */
51
    public function send($params)
52
    {
53
        try {
54
            $sendsms_url = "?company={$this->company}&user={$this->username}&password={$this->password}&gateway=L&mode=BUK&type=TX&hp={$params['hp']}&mesg={$params['mesg']}&charge=0&maskid=1&convert=0";
55
56
            $response = $this->httpClient->request('GET', $this->apiUrl.$sendsms_url);
57
58
            $stream = $response->getBody();
59
60
            $content = $stream->getContents();
61
62
            $response = json_decode((string) $response->getBody(), true);
63
64
            if ($content == 'E01') {
65
                throw new \Exception('E01');
66
            }
67
68
            return $response;
69
        } catch (DomainException $exception) {
70
            throw CouldNotSendNotification::exceptionGoSmsRespondedWithAnError($exception);
71
        } catch (\Exception $exception) {
72
            throw CouldNotSendNotification::couldNotCommunicateWithGoSms($exception);
73
        }
74
    }
75
}
76