Completed
Push — master ( 7087b8...dc534c )
by Kazi Mainuddin
11s
created

Linkmobility::send()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 26
Code Lines 15

Duplication

Lines 6
Ratio 23.08 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 26
rs 8.8571
cc 3
eloc 15
nc 3
nop 0
1
<?php
2
namespace Tzsk\Sms\Drivers;
3
4
use GuzzleHttp\Client;
5
use Tzsk\Sms\Contract\SendSmsInterface;
6
7
class Linkmobility extends MasterDriver implements SendSmsInterface
8
{
9
    /**
10
     * Textlocal Settings.
11
     *
12
     * @var object|null
13
     */
14
    protected $settings = null;
15
16
    /**
17
     * Http Client.
18
     *
19
     * @var Client|null
20
     */
21
    protected $client = null;
22
23
    /**
24
     * Construct the class with the relevant settings.
25
     *
26
     * SendSmsInterface constructor.
27
     * @param array $settings
28
     */
29
    public function __construct($settings)
30
    {
31
        $this->settings = (object) $settings;
32
        $this->client = new Client();
33
    }
34
35
    /**
36
     * Send text message and return response.
37
     *
38
     * @return mixed
39
     */
40
    public function send()
41
    {
42
        $numbers = implode(",", $this->recipients);
43
44
        $response = $this->client->request("POST", $this->settings->url, [
45
            "form_params" => [
46
                "USER" => $this->settings->username,
47
                "PW" => $this->settings->password,
48
                "RCV"  => $numbers,
49
                "SND" => urlencode($this->settings->sender),
50
                "TXT" => $this->body,
51
            ],
52
        ]);
53
54 View Code Duplication
        if ($response->getStatusCode() != 200) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
55
            return (object) ["status" => false, "message" => "Request Error. " . $response->getReasonPhrase()];
56
        }
57
58
        $data = json_decode((string) $response->getBody(), true);
59
60 View Code Duplication
        if ($data["status"] != "success") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
61
            return (object) ["status" => false, "message" => "Something went wrong.", "data" => $data];
62
        }
63
64
        return (object) array_merge($data, ["status" => true]);
65
    }
66
}
67