Kavenegar   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A send() 0 12 3
1
<?php
2
3
namespace Tzsk\Sms\Drivers;
4
5
use Kavenegar\KavenegarApi;
6
use Tzsk\Sms\Abstracts\Driver;
7
8
class Kavenegar extends Driver
9
{
10
    /**
11
     * Kavenegar Settings.
12
     *
13
     * @var object
14
     */
15
    protected $settings;
16
17
    /**
18
     * Kavenegar Client.
19
     *
20
     * @var null|KavenegarApi
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 KavenegarApi($this->settings->apiKey);
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
            $response->put(
46
                $recipient,
47
                $this->client->Send($this->settings->from, $recipient, $this->body)
48
            );
49
        }
50
51
        return (count($this->recipients) == 1) ? $response->first() : $response;
52
    }
53
}
54