Completed
Push — master ( 480577...25417b )
by Kazi Mainuddin
01:43 queued 10s
created

SmsGatewayMe::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Tzsk\Sms\Drivers;
4
5
use Tzsk\Sms\Abstracts\Driver;
6
use SMSGatewayMe\Client\ApiClient;
7
use SMSGatewayMe\Client\Configuration;
8
use SMSGatewayMe\Client\Api\MessageApi;
9
use SMSGatewayMe\Client\Model\SendMessageRequest;
10
11
class SmsGatewayMe extends Driver
12
{
13
    /**
14
     * SMSGatewayMe Settings.
15
     *
16
     * @var object
17
     */
18
    protected $settings;
19
20
    /**
21
     * SMSGatewayMe Client.
22
     *
23
     * @var SMSGatewayMe\Client\Api\MessageApi
24
     */
25
    protected $client;
26
27
    /**
28
     * Construct the class with the relevant settings.
29
     *
30
     * SendSmsInterface constructor.
31
     * @param $settings object
32
     */
33
    public function __construct($settings)
34
    {
35
        $this->settings = (object) $settings;
36
37
        $config = Configuration::getDefaultConfiguration();
38
        $config->setApiKey('Authorization', $this->settings->apiToken);
39
        $apiClient = new ApiClient($config);
40
        $this->client = new MessageApi($apiClient);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \SMSGatewayMe\Client...\MessageApi($apiClient) of type object<SMSGatewayMe\Client\Api\MessageApi> is incompatible with the declared type object<Tzsk\Sms\Drivers\...\Client\Api\MessageApi> 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...
41
    }
42
43
    /**
44
     * Send text message and return response.
45
     *
46
     * @return object
47
     */
48
    public function send()
49
    {
50
        $response = collect();
51
        foreach ($this->recipients as $recipient) {
52
            $response->put(
53
                $recipient,
54
                $this->client->sendMessages($this->payload($recipient))
55
            );
56
        }
57
58
        return (count($this->recipients) == 1) ? $response->first() : $response;
59
    }
60
61
    /**
62
     * @param string $recipient
63
     * @return array
64
     */
65
    protected function payload($recipient)
66
    {
67
        return new SendMessageRequest([
68
            'phoneNumber' => $recipient,
69
            'message' => $this->body,
70
            'deviceId' => $this->settings->from
71
        ]);
72
    }
73
}
74