BetaSms   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 20.69 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 64.29%

Importance

Changes 0
Metric Value
dl 12
loc 58
ccs 18
cts 28
cp 0.6429
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 12 12 2
B send() 0 32 6

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
 * Created by PhpStorm.
4
 * User: Djunehor
5
 * Date: 1/22/2019
6
 * Time: 9:36 AM.
7
 */
8
9
namespace Djunehor\Sms\Concrete;
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 7 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 7
        $this->username = config('laravel-sms.beta_sms.username');
25 7
        $this->password = config('laravel-sms.beta_sms.password');
26
27 7
        if ($message) {
28
            $this->text($message);
29
        }
30
31 7
        $this->client = $this->getInstance();
32 7
        $this->request = new Request('POST', $this->baseUrl.'api/');
33 7
    }
34
35
    /**
36
     * @param null $text
37
     * @return bool
38
     */
39 1
    public function send($text = null): bool
40
    {
41 1
        if ($text) {
42
            $this->setText($text);
43
        }
44
        try {
45 1
            $response = $this->client->send($this->request, [
46
                'form_params' => [
47 1
                    'mobiles' => implode(',', $this->recipients),
48 1
                    'sender' => $this->sender ?? config('laravel-sms.sender'),
49 1
                    'username' => $this->username,
50 1
                    'password' => $this->password,
51 1
                    'message' => $this->text,
52
                ],
53
            ]);
54
55 1
            $response = json_decode($response->getBody()->getContents(), true);
56 1
            $this->response = array_key_exists('status', $response) ? $response['status'] : $response['error'];
57
58 1
            return $this->response == 'OK' ? true : false;
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