Completed
Push — master ( af7c86...2260a0 )
by Kazi Mainuddin
03:11
created

Textlocal   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 19.05 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 12
loc 63
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A send() 12 12 3
A payload() 0 12 1

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
namespace Tzsk\Sms\Drivers;
4
5
use GuzzleHttp\Client;
6
use Tzsk\Sms\Abstracts\Driver;
7
8
class Textlocal extends Driver
9
{
10
    /**
11
     * Textlocal Settings.
12
     *
13
     * @var object
14
     */
15
    protected $settings;
16
17
    /**
18
     * Http Client.
19
     *
20
     * @var Client
21
     */
22
    protected $client;
23
24
    /**
25
     * Construct the class with the relevant settings.
26
     *
27
     * SendSmsInterface constructor.
28
     * @param array $settings
29
     */
30
    public function __construct($settings)
31
    {
32
        $this->settings = (object) $settings;
33
        $this->client = new Client();
34
    }
35
36
    /**
37
     * Send text message and return response.
38
     *
39
     * @return mixed
40
     */
41 View Code Duplication
    public function send()
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...
42
    {
43
        $response = collect();
44
        foreach ($this->recipients as $recipient) {
45
            $response->put(
46
                $recipient,
47
                $this->client->request('POST', $this->settings->url, $this->payload($recipient))
48
            );
49
        }
50
51
        return (count($this->recipients) == 1) ? $response->first() : $response;
52
    }
53
54
    /**
55
     * @param string $recipient
56
     * @return array
57
     */
58
    public function payload($recipient)
59
    {
60
        return [
61
            'form_params' => [
62
                'username' => $this->settings->username,
63
                'hash' => $this->settings->hash,
64
                'numbers' => $recipient,
65
                'sender' => urlencode($this->settings->sender),
66
                'message' => $this->body,
67
            ],
68
        ];
69
    }
70
}
71