Completed
Push — master ( e6f297...cd788c )
by Kazi Mainuddin
12s
created

Kavenegar::getSmsResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
namespace Tzsk\Sms\Drivers;
3
4
use Kavenegar\KavenegarApi;
5
use Tzsk\Sms\Abstracts\Driver;
6
7
class Kavenegar extends Driver
8
{
9
    /**
10
     * Kavenegar Settings.
11
     *
12
     * @var null|object
13
     */
14
    protected $settings = null;
15
16
    /**
17
     * Kavenegar Client.
18
     *
19
     * @var null|KavenegarApi
20
     */
21
    protected $client = null;
22
23
    /**
24
     * Construct the class with the relevant settings.
25
     *
26
     * SendSmsInterface constructor.
27
     * @param $settings object
28
     */
29
    public function __construct($settings)
30
    {
31
        $this->settings = (object) $settings;
32
        $this->client = new KavenegarApi($this->settings->apiKey);
33
    }
34
35
    /**
36
     * Send text message and return response.
37
     *
38
     * @return object
39
     */
40 View Code Duplication
    public function send()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $response = [];
43
        foreach ($this->recipients as $recipient) {
44
            $sms = $this->client->Send(
45
                $this->settings->from,
46
                $recipient,
47
                $this->body
48
            );
49
            $response[$recipient]['data'] = $this->getSmsResponse($sms[0]);
50
            $response[$recipient]['status'] = true;
51
        }
52
53
        return (object) $response;
54
    }
55
56
    /**
57
     * Get the Kavenegar Response.
58
     *
59
     * @param $sms
60
     * @return object
61
     */
62
    protected function getSmsResponse($sms)
63
    {
64
        $attributes = [
65
            'messageid', 'message', 'status', 'statustext',
66
            'sender', 'receptor', 'date', 'cost',
67
        ];
68
69
        $res = [];
70
        foreach ($attributes as $attribute) {
71
            $res[$attribute] = $sms->$attribute;
72
        }
73
74
        return (object) $res;
75
    }
76
}
77