Completed
Pull Request — master (#22)
by mahdi
01:31
created

Tsms   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A send() 0 21 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
     * Smsir 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
        $this->client = new SoapClient($this->settings->url);
34
    }
35
36
    /**
37
     * Send text message and return response.
38
     *
39
     * @return object
40
     * @throws \GuzzleHttp\Exception\GuzzleException
41
     */
42
    public function send()
43
    {
44
        $response = collect();
45
        foreach ($this->recipients as $recipient) {
46
            $result = $this
47
                ->client
48
                ->sendSms(
49
                    $this->settings->username,
50
                    $this->settings->password,
51
                    [$this->settings->from],
52
                    [$recipient],
53
                    [$this->body],
54
                    [],
55
                    rand()
56
                );
57
58
            $response->put($recipient, $result);
59
        }
60
61
        return (count($this->recipients) == 1) ? $response->first() : $response;
62
    }
63
}
64