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

MultiTexter::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 14
loc 14
ccs 8
cts 8
cp 1
crap 2
rs 9.7998
c 0
b 0
f 0
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