PlaySmsClient   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A send() 0 17 2
1
<?php
2
3
namespace CoreProc\NotificationChannels\PlaySms;
4
5
use CoreProc\NotificationChannels\PlaySms\Exceptions\CouldNotSendNotification;
6
use GuzzleHttp\Client;
7
use GuzzleHttp\Exception\RequestException;
8
9
class PlaySmsClient
10
{
11
    private $client;
12
    private $apiKey;
13
    private $username;
14
15
    public function __construct($baseUrl, $username, $apiKey, $options = [])
16
    {
17
        $this->username = $username;
18
        $this->apiKey = $apiKey;
19
        $this->client = new Client(array_merge(
20
            ['base_uri' => $baseUrl],
21
            $options
22
        ));
23
    }
24
25
    /**
26
     * @param $mobileNumber
27
     * @param $message
28
     * @throws CouldNotSendNotification
29
     */
30
    public function send($mobileNumber, $message)
31
    {
32
        try {
33
            $this->client->get('/index.php', [
34
                'query' => [
35
                    'app' => 'ws',
36
                    'u' => $this->username,
37
                    'h' => $this->apiKey,
38
                    'op' => 'pv',
39
                    'to' => $mobileNumber,
40
                    'msg' => $message,
41
                ],
42
            ]);
43
        } catch (RequestException $e) {
44
            throw new CouldNotSendNotification("Failed to call PlaySMS API. Endpoint responded with {$e->getCode()}.");
45
        }
46
    }
47
}
48