Completed
Push — master ( 3b68b0...54dc48 )
by Kazi Mainuddin
01:36
created

Farazsms::send()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 0
dl 15
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
namespace Tzsk\Sms\Drivers;
4
5
use Tzsk\Sms\Abstracts\Driver;
6
use \SoapClient;
7
8 View Code Duplication
class Farazsms extends Driver
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    /**
11
     * Tsms Settings.
12
     *
13
     * @var null|object
14
     */
15
    protected $settings;
16
17
    /**
18
     * Smsir Client.
19
     *
20
     * @var null|SoapClient
21
     */
22
    protected $client;
23
24
    /**
25
     * Construct the class with the relevant settings.
26
     *
27
     * @param $settings
28
     * @throws \SoapFault
29
     */
30
    public function __construct($settings)
31
    {
32
        $this->settings = (object) $settings;
33
        $this->client = new Client();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Tzsk\Sms\Drivers\Client() of type object<Tzsk\Sms\Drivers\Client> is incompatible with the declared type null|object<SoapClient> of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
    }
35
36
    /**
37
     * Send text message and return response.
38
     *
39
     * @return object
40
     * @throws \GuzzleHttp\Exception\GuzzleException
41
     */
42
    public function send()
43
    {
44
        $response = collect();
45
46
        foreach ($this->recipients as $recipient) {
47
            $result = $this->client->request(
0 ignored issues
show
Bug introduced by
The method request() does not exist on SoapClient. Did you maybe mean __doRequest()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
48
                'POST',
49
                $this->settings->url,
50
                $this->payload($recipient)
51
            );
52
            $response->put($recipient, json_decode($result));
53
        }
54
55
        return (count($this->recipients) == 1) ? $response->first() : $response;
56
    }
57
58
    /**
59
     * @param string $recipient
60
     * @param string $token
0 ignored issues
show
Bug introduced by
There is no parameter named $token. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
61
     * @return array
62
     */
63
    protected function payload($recipient)
64
    {
65
        return [
66
            'uname' => $this->settings->username,
67
            'pass' => $this->settings->password,
68
            'from' => $this->settings->from,
69
            'message' => $this->body,
70
            'to' => json_encode([$recipient]),
71
            'op'=>'send'
72
        ];
73
    }
74
}
75