Test Failed
Pull Request — master (#4)
by
unknown
32:10
created

BetaSms::send()   A

Complexity

Conditions 5
Paths 18

Size

Total Lines 32

Duplication

Lines 32
Ratio 100 %

Importance

Changes 0
Metric Value
dl 32
loc 32
c 0
b 0
f 0
rs 9.0968
cc 5
nc 18
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Djunehor
5
 * Date: 1/22/2019
6
 * Time: 9:36 AM.
7
 */
8
9
namespace Djunehor\Sms\App\Drivers;
10
11
use GuzzleHttp\Exception\ClientException;
12
use GuzzleHttp\Psr7\Request;
13
14
class BetaSms extends Sms
15
{
16
    private $baseUrl = 'http://login.betasms.com.ng/';
17
18
    /**
19
     * Class Constructor.
20
     * @param null $message
21
     */
22 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...
23
    {
24
        $this->username = config('laravel-sms.beta_sms.username');
25
        $this->password = config('laravel-sms.beta_sms.password');
26
27
        if ($message) {
28
            $this->text($message);
29
        }
30
31
        $this->client = $this->getInstance();
32
        $this->request = new Request('POST', $this->baseUrl.'api/');
33
    }
34
35
    /**
36
     * @param null $text
37
     * @return bool
38
     */
39 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...
40
    {
41
        if ($text) {
42
            $this->setText($text);
43
        }
44
        try {
45
            $response = $this->client->send($this->request, [
46
                'form_params' => [
47
                    'mobiles' => implode(',', $this->recipients),
48
                    'sender' => $this->sender ?? config('laravel-sms.sender'),
49
                    'username' => $this->username,
50
                    'password' => $this->password,
51
                    'message' => $this->text,
52
                ],
53
            ]);
54
55
            $response = json_decode($response->getBody()->getContents(), true);
56
            $this->response = array_key_exists('status', $response) ? $response['status'] : $response['error'];
57
58
            return $this->response == 'OK';
59
        } catch (ClientException $e) {
60
            logger()->error('HTTP Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage());
61
            $this->httpError = $e;
62
63
            return false;
64
        } catch (\Exception $e) {
65
            logger()->error('SMS Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage());
66
            $this->httpError = $e;
67
68
            return false;
69
        }
70
    }
71
}
72