SMSOffice   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
dl 0
loc 49
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A send() 0 15 3
1
<?php
2
3
namespace Gabievi\LaravelSMSOffice;
4
5
use DomainException;
6
use GuzzleHttp\Client as HttpClient;
7
8
class SMSOffice
9
{
10
    /** @var string */
11
    protected $apiUrl = 'http://smsoffice.ge/api/v2/send';
12
13
    /** @var HttpClient */
14
    protected $httpClient;
15
16
    /** @var string */
17
    protected $key;
18
19
    /** @var string */
20
    protected $sender;
21
22
    /**
23
     * SMSOffice constructor.
24
     * @param $key
25
     * @param $sender
26
     */
27 7
    public function __construct($key, $sender)
28
    {
29 7
        $this->key = $key;
30 7
        $this->sender = $sender;
31
32 7
        $this->httpClient = new HttpClient([
33 7
            'timeout'         => 5,
34
            'connect_timeout' => 5,
35
        ]);
36 7
    }
37
38
    /**
39
     * @param $params
40
     * @throws DomainException
41
     */
42 3
    public function send($params)
43
    {
44
        $base = [
45 3
            'key'    => urlencode($this->key),
46 3
            'sender' => urlencode($this->sender),
47
        ];
48
49 3
        $params = array_merge($params, $base);
50 3
        $url = $this->apiUrl.'?'.http_build_query($params);
51
52 3
        $response = $this->httpClient->get($url);
53 3
        $response = json_decode((string) $response->getBody(), true);
54
55 3
        if (isset($response['ErrorCode']) && (int) $response['ErrorCode'] !== 0) {
56 3
            throw new DomainException($response['Message'], $response['ErrorCode']);
57
        }
58
    }
59
}
60