Tsms::send()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 0
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
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