MultiTexter::send()   A
last analyzed

Complexity

Conditions 5
Paths 22

Size

Total Lines 33

Duplication

Lines 33
Ratio 100 %

Code Coverage

Tests 11
CRAP Score 7.2781

Importance

Changes 0
Metric Value
cc 5
nc 22
nop 1
dl 33
loc 33
ccs 11
cts 20
cp 0.55
crap 7.2781
rs 9.0808
c 0
b 0
f 0
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