GoldSms247   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 94
Duplicated Lines 12.77 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 59.38%

Importance

Changes 0
Metric Value
dl 12
loc 94
ccs 19
cts 32
cp 0.5938
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 12 12 2
A getResponse() 0 6 2
B send() 0 33 7

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
/**
3
 * Created by PhpStorm.
4
 * User: Djunehor
5
 * Date: 1/22/2019
6
 * Time: 9:36 AM.
7
 */
8
9
namespace Djunehor\Sms\Concrete;
10
11
use GuzzleHttp\Exception\ClientException;
12
use GuzzleHttp\Psr7\Request;
13
14
class GoldSms247 extends Sms
15
{
16
    private $responseCodes = [
17
        'OK' => 'Successful',
18
19
        '2904' => 'SMS Sending Failed',
20
21
        '2905' => 'Invalid username/password combination',
22
23
        '2906' => 'Credit exhausted',
24
25
        '2907' => 'Gateway unavailable',
26
27
        '2908' => 'Invalid schedule date format',
28
29
        '2909' => 'Unable to schedule',
30
31
        '2910' => 'Username is empty',
32
33
        '2911' => 'Password is empty',
34
35
        '2912' => 'Recipient is empty',
36
37
        '2913=Message is empty',
38
39
        '2914=Sender is empty',
40
41
        '2915' => 'One or more required fields are empty',
42
    ];
43
44
    private $baseUrl = 'http://goldsms247.com/components/com_spc/';
45
46
    /**
47
     * Class Constructor.
48
     * @param null $message
49
     */
50 1 View Code Duplication
    public function __construct($message = null)
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...
51
    {
52 1
        $this->username = config('laravel-sms.gold_sms_247.username');
53 1
        $this->password = config('laravel-sms.gold_sms_247.password');
54
55 1
        if ($message) {
56
            $this->text($message);
57
        }
58
59 1
        $this->client = self::getInstance();
60 1
        $this->request = new Request('GET', $this->baseUrl.'smsapi.php');
61 1
    }
62
63
    public function getResponse()
64
    {
65
        $split = explode(' ', $this->response);
66
67
        return array_key_exists($split[0], $this->responseCodes) ? $this->responseCodes[$split[0]] : '';
68
    }
69
70
    /**
71
     * @param null $text
72
     * @return bool
73
     */
74 1
    public function send($text = null): bool
75
    {
76 1
        if ($text) {
77
            $this->setText($text);
78
        }
79
        try {
80 1
            $response = $this->client->send($this->request, [
81
                'query' => [
82 1
                    'username' => $this->username,
83 1
                    'password' => $this->password,
84 1
                    'recipient' => implode(',', $this->recipients),
85 1
                    'sender' => $this->sender ?? config('laravel-sms.sender'),
86 1
                    'message' => $this->text,
87
                ],
88
            ]);
89
90 1
            $response = json_decode($response->getBody()->getContents(), true);
91 1
            $split = explode(' ', $response);
92 1
            $this->response = array_key_exists($split[0], $this->responseCodes) ? $this->responseCodes[$split[0]] : '';
93
94 1
            return (! $split[0] || $split[0] == 'OK') ? true : false;
95
        } catch (ClientException $e) {
96
            logger()->error('HTTP Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage());
97
            $this->httpError = $e;
98
99
            return false;
100
        } catch (\Exception $e) {
101
            logger()->error('SMS Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage());
102
            $this->httpError = $e;
103
104
            return false;
105
        }
106
    }
107
}
108