Completed
Push — master ( af7c86...2260a0 )
by Kazi Mainuddin
03:11
created

Twilio::getSmsResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Tzsk\Sms\Drivers;
4
5
use Twilio\Rest\Client;
6
use Tzsk\Sms\Abstracts\Driver;
7
8
class Twilio extends Driver
9
{
10
    /**
11
     * Twilio Settings.
12
     *
13
     * @var object
14
     */
15
    protected $settings;
16
17
    /**
18
     * Twilio Client.
19
     *
20
     * @var Client
21
     */
22
    protected $client;
23
24
    /**
25
     * Construct the class with the relevant settings.
26
     *
27
     * SendSmsInterface constructor.
28
     * @param $settings object
29
     */
30
    public function __construct($settings)
31
    {
32
        $this->settings = (object) $settings;
33
        $this->client = new Client($this->settings->sid, $this->settings->token);
34
    }
35
36
    /**
37
     * Send text message and return response.
38
     *
39
     * @return object
40
     */
41
    public function send()
42
    {
43
        $response = collect();
44
        foreach ($this->recipients as $recipient) {
45
            $result = $this->client->account->messages->create(
0 ignored issues
show
Bug introduced by
The property messages does not seem to exist. Did you mean _messages?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
46
                $recipient,
47
                ['from' => $this->settings->from, 'body' => $this->body]
48
            );
49
50
            $response->put($recipient, $result);
51
        }
52
53
        return (count($this->recipients) == 1) ? $response->first() : $response;
54
    }
55
}
56