Completed
Push — master ( 5c498e...edddde )
by Hilmi Erdem
01:29
created

JetSmsHttpClient::getSendDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Erdemkeren\JetSms\Http\Clients;
4
5
use GuzzleHttp\Client;
6
use Erdemkeren\JetSms\ShortMessage;
7
use Erdemkeren\JetSms\ShortMessageCollection;
8
use Erdemkeren\JetSms\Http\Responses\JetSmsHttpResponse;
9
use Erdemkeren\JetSms\Http\Responses\JetSmsResponseInterface;
10
11
/**
12
 * Class JetSmsHttpClient.
13
 */
14
class JetSmsHttpClient implements JetSmsClientInterface
15
{
16
    /**
17
     * The Http client.
18
     *
19
     * @var Client
20
     */
21
    private $httpClient;
22
23
    /**
24
     * The JetSms xml request url.
25
     *
26
     * @var string
27
     */
28
    private $url;
29
30
    /**
31
     * The auth username.
32
     *
33
     * @var string
34
     */
35
    private $username;
36
37
    /**
38
     * The auth password.
39
     *
40
     * @var string
41
     */
42
    private $password;
43
44
    /**
45
     * The outbox name.
46
     *
47
     * @var string
48
     */
49
    private $outboxName;
50
51
    /**
52
     * XmlJetSmsClient constructor.
53
     *
54
     * @param Client $client
55
     * @param string $url
56
     * @param string $username
57
     * @param string $password
58
     * @param string $outboxName
59
     */
60 2 View Code Duplication
    public function __construct(Client $client, $url, $username, $password, $outboxName)
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...
61
    {
62 2
        $this->httpClient = $client;
63 2
        $this->url = $url;
64 2
        $this->username = $username;
65 2
        $this->password = $password;
66 2
        $this->outboxName = $outboxName;
67 2
    }
68
69
    /**
70
     * Send a short message using the JetSms services.
71
     *
72
     * @param  ShortMessage $shortMessage
73
     *
74
     * @return JetSmsResponseInterface
75
     */
76 1 View Code Duplication
    public function sendShortMessage(ShortMessage $shortMessage)
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...
77
    {
78 1
        $guzzleResponse = $this->httpClient->request('POST', $this->url, [
79 1
            'form_params' => array_merge(
80 1
                $shortMessage->toArray(),
81 1
                $this->getSendDate(),
82 1
                $this->getCredentials()
83 1
            ),
84 1
        ]);
85
86 1
        return new JetSmsHttpResponse((string) $guzzleResponse->getBody());
87
    }
88
89
    /**
90
     * Send multiple short messages using the JetSms services.
91
     *
92
     * @param  ShortMessageCollection $shortMessageCollection
93
     *
94
     * @return JetSmsResponseInterface
95
     */
96 1 View Code Duplication
    public function sendShortMessages(ShortMessageCollection $shortMessageCollection)
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...
97
    {
98 1
        $guzzleResponse = $this->httpClient->request('POST', $this->url, [
99 1
            'form_params' => array_merge(
100 1
                $shortMessageCollection->toArray(),
101 1
                $this->getSendDate(),
102 1
                $this->getCredentials()
103 1
            ),
104 1
        ]);
105
106 1
        return new JetSmsHttpResponse((string) $guzzleResponse->getBody());
107
    }
108
109
    /**
110
     * Get the send date of the contents.
111
     *
112
     * @return array
113
     */
114 2
    private function getSendDate()
115
    {
116
        return [
117 2
            'SendDate' => null,
118 2
        ];
119
    }
120
121
    /**
122
     * Get the auth credentials array.
123
     *
124
     * @return array
125
     */
126 2
    private function getCredentials()
127
    {
128
        return [
129 2
            'Username'       => $this->username,
130 2
            'Password'       => $this->password,
131 2
            'TransmissionID' => $this->outboxName,
132 2
        ];
133
    }
134
}
135