Passed
Push — master ( 7d6da9...87fa1f )
by Zacchaeus
01:25 queued 10s
created

SmartSmsSolutions::send()   A

Complexity

Conditions 5
Paths 18

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 7.2781

Importance

Changes 0
Metric Value
cc 5
nc 18
nop 1
dl 0
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
 * 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