Tsms   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 20 3
1
<?php
2
3
namespace Tzsk\Sms\Drivers;
4
5
use Tzsk\Sms\Abstracts\Driver;
6
use \SoapClient;
7
8
class Tsms extends Driver
9
{
10
    /**
11
     * Tsms Settings.
12
     *
13
     * @var null|object
14
     */
15
    protected $settings;
16
17
    /**
18
     * Tsms Client.
19
     *
20
     * @var null|SoapClient
21
     */
22
    protected $client;
23
24
    /**
25
     * Construct the class with the relevant settings.
26
     *
27
     * @param $settings
28
     * @throws \SoapFault
29
     */
30
    public function __construct($settings)
31
    {
32
        $this->settings = (object) $settings;
33
    }
34
35
    /**
36
     * Send text message and return response.
37
     *
38
     * @return object
39
     * @throws \GuzzleHttp\Exception\GuzzleException
40
     */
41
    public function send()
42
    {
43
        $this->client = new SoapClient($this->settings->url);
44
        $response = collect();
45
        foreach ($this->recipients as $recipient) {
46
            $result = $this->client->sendSms(
47
                $this->settings->username,
48
                $this->settings->password,
49
                [$this->settings->from],
50
                [$recipient],
51
                [$this->body],
52
                [],
53
                rand()
54
            );
55
56
            $response->put($recipient, $result);
57
        }
58
59
        return (count($this->recipients) == 1) ? $response->first() : $response;
60
    }
61
}
62