Passed
Push — master ( fa1980...7d6da9 )
by Zacchaeus
01:11 queued 10s
created

MultiTexter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 22.95 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 67.86%

Importance

Changes 0
Metric Value
dl 14
loc 61
ccs 19
cts 28
cp 0.6786
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 14 14 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
namespace Djunehor\Sms\Concrete;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Exception\ClientException;
7
use Illuminate\Support\Facades\Log;
8
9
class MultiTexter extends Sms
10
{
11
    private $baseUrl = 'https://app.multitexter.com/v2/app/';
12
13
    /**
14
     * Class Constructor.
15
     * @param null $message
16
     */
17 2 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...
18
    {
19 2
        $this->username = config('laravel-sms.multitexter.username');
20 2
        $this->password = config('laravel-sms.multitexter.password');
21 2
        if ($message) {
22 1
            $this->text($message);
23
        }
24 2
        $this->client = new Client([
25 2
            'base_uri' => $this->baseUrl,
26
            'headers' => [
27
                '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',
28
            ],
29
        ]);
30 2
    }
31
32
    /**
33
     * @param null $text
34
     * @return bool
35
     */
36 2
    public function send($text = null): bool
37
    {
38 2
        if ($text) {
39
            $this->setText($text);
40
        }
41
42
        try {
43 2
            $response = $this->client->post('sms', [
44
                'query' => [
45 2
                    'recipients' => implode(',', $this->recipients),
46 2
                    'sender_name' => $this->sender ?? config('laravel-sms.sender'),
47 2
                    'email' => $this->username,
48 2
                    'password' => $this->password,
49 2
                    'message' => $this->text,
50
                ],
51
            ]);
52
53 2
            $response = json_decode($response->getBody()->getContents(), true);
54 2
            $this->response = $response['msg'];
55
56 2
            return $response['status'] == '1' ? true : false;
57
        } catch (ClientException $e) {
58
            Log::info('HTTP Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage());
59
            $this->httpError = $e;
60
61
            return false;
62
        } catch (\Exception $e) {
63
            Log::info('SMS Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage());
64
            $this->httpError = $e;
65
66
            return false;
67
        }
68
    }
69
}
70