SmartSmsSolutions   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 23.81 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 64.29%

Importance

Changes 0
Metric Value
dl 15
loc 63
ccs 18
cts 28
cp 0.6429
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 15 15 2
A send() 0 33 5

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: 5/25/2019
6
 * Time: 5:51 PM.
7
 */
8
9
namespace Djunehor\Sms\Concrete;
10
11
use GuzzleHttp\Exception\ClientException;
12
use GuzzleHttp\Psr7\Request;
13
14
class SmartSmsSolutions extends Sms
15
{
16
    private $baseUrl = 'https://smartsmssolutions.com/api/';
17
18
    /**
19
     * Class Constructor.
20
     *
21
     * @param null $message
22
     */
23 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...
24
    {
25 1
        $this->username = config('laravel-sms.smart_sms.token');
26 1
        if ($message) {
27
            $this->text($message);
28
        }
29
30
        $headers = [
31 1
            'Content-Type' => 'Content-type: application/x-www-form-urlencoded',
32
            'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36 OPR/47.0.2631.39',
33
        ];
34
35 1
        $this->client = $this->getInstance();
36 1
        $this->request = new Request('GET', $this->baseUrl.'json.php?', $headers);
37 1
    }
38
39
    /**
40
     * @param null $text
41
     * @return bool
42
     */
43 1
    public function send($text = null): bool
44
    {
45 1
        if ($text) {
46
            $this->setText($text);
47
        }
48
49
        try {
50 1
            $response = $this->client->send($this->request, [
51
                'query' => [
52 1
                    'token' => $this->username,
53 1
                    'type' => 0,
54 1
                    'to' => implode(',', $this->recipients),
55 1
                    'sender' => $this->sender ?? config('laravel-sms.sender'),
56 1
                    'message' => $this->text,
57 1
                    'routing' => 2, //basic route = 2
58
                ],
59
            ]);
60
61 1
            $this->response = json_decode($response->getBody()->getContents(), true);
62
63 1
            return array_key_exists('successful', $this->response) ? true : false;
64
        } catch (ClientException $e) {
65
            logger()->error('HTTP Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage());
66
            $this->httpError = $e;
67
68
            return false;
69
        } catch (\Exception $e) {
70
            logger()->error('SMS Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage());
71
            $this->httpError = $e;
72
73
            return false;
74
        }
75
    }
76
}
77