ToOne::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 0
c 2
b 1
f 1
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace MeysamZnd\HostiranSmsProvider;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Exception\GuzzleException;
7
use MeysamZnd\HostiranSmsProvider\Interfaces\Sms;
8
9
class ToOne implements Sms
10
{
11
    public function __construct()
12
    {
13
    }
14
15
    /**
16
     * @param string $url
17
     * @param array $data
18
     * @return array
19
     * @throws GuzzleException
20
     */
21
    public function send(string $url, array $data): array
22
    {
23
        try {
24
            $client = new Client();
25
            $request = $client->post($url, ['json' => $data]);
26
            $response = [
27
                'status' => true,
28
                'providerResult' => json_decode($request->getBody()->getContents(), true),
29
            ];
30
        } catch (\Exception $e) {
31
            $response = [
32
                'status' => false,
33
                'providerResult' => $e->getMessage(),
34
            ];
35
        }
36
37
        return $response;
38
    }
39
}
40