MultiTexter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 76.27 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 67.86%

Importance

Changes 0
Metric Value
dl 45
loc 59
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() 12 12 2
A send() 33 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\Exception\ClientException;
6
use GuzzleHttp\Psr7\Request;
7
8
class MultiTexter extends Sms
9
{
10
    private $baseUrl = 'https://app.multitexter.com/v2/app/';
11
12
    /**
13
     * Class Constructor.
14
     * @param null $message
15
     */
16 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...
17
    {
18 2
        $this->username = config('laravel-sms.multitexter.username');
19 2
        $this->password = config('laravel-sms.multitexter.password');
20
21 2
        if ($message) {
22 1
            $this->text($message);
23
        }
24
25 2
        $this->client = self::getInstance();
26 2
        $this->request = new Request('POST', $this->baseUrl.'sms');
27 2
    }
28
29
    /**
30
     * @param null $text
31
     * @return bool
32
     */
33 2 View Code Duplication
    public function send($text = null): bool
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...
34
    {
35 2
        if ($text) {
36
            $this->setText($text);
37
        }
38
39
        try {
40 2
            $response = $this->client->send($this->request, [
41
                'form_params' => [
42 2
                    'recipients' => implode(',', $this->recipients),
43 2
                    'sender_name' => $this->sender ?? config('laravel-sms.sender'),
44 2
                    'email' => $this->username,
45 2
                    'password' => $this->password,
46 2
                    'message' => $this->text,
47
                ],
48
            ]);
49
50 2
            $response = json_decode($response->getBody()->getContents(), true);
51 2
            $this->response = $response['msg'];
52
53 2
            return $response['status'] == '1' ? true : false;
54
        } catch (ClientException $e) {
55
            logger()->error('HTTP Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage());
56
            $this->httpError = $e;
57
58
            return false;
59
        } catch (\Exception $e) {
60
            logger()->error('SMS Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage());
61
            $this->httpError = $e;
62
63
            return false;
64
        }
65
    }
66
}
67