Nexmo::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Tzsk\Sms\Drivers;
4
5
use Nexmo\Message\Text;
6
use Nexmo\Client;
7
use Tzsk\Sms\Abstracts\Driver;
8
use Nexmo\Client\Credentials\Basic;
9
10
class Nexmo extends Driver
11
{
12
    /**
13
     * Settings.
14
     *
15
     * @var object
16
     */
17
    protected $settings;
18
19
    /**
20
     * Client.
21
     *
22
     * @var Client
23
     */
24
    protected $client;
25
26
    /**
27
     * Construct the class with the relevant settings.
28
     *
29
     * SendSmsInterface constructor.
30
     * @param $settings object
31
     */
32
    public function __construct($settings)
33
    {
34
        $this->settings = (object) $settings;
35
        $this->client = new Client(
36
            new Basic($this->settings->key, $this->settings->secret)
37
        );
38
    }
39
40
    /**
41
     * Send text message and return response.
42
     *
43
     * @return object
44
     */
45
    public function send()
46
    {
47
        $response = collect();
48
        foreach ($this->recipients as $recipient) {
49
            $text = new Text($recipient, $this->settings->from, $this->body);
50
            $response->put($recipient, $this->client->message()->send($text));
51
        }
52
53
        return (count($this->recipients) == 1) ? $response->first() : $response;
54
    }
55
}
56