Completed
Pull Request — master (#7)
by
unknown
05:13
created

Linkmobility::send()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 27
Code Lines 15

Duplication

Lines 6
Ratio 22.22 %

Importance

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