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

Linkmobility   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 10 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 6
loc 60
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B send() 6 26 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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