Reusable   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A request() 0 19 2
1
<?php
2
3
namespace MeysamZnd\KaveNegarSmsProvider\Helper;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Exception\GuzzleException;
7
8
class Reusable
9
{
10
    /**
11
     * @param string $url
12
     * @param array $data
13
     * @return array
14
     * @throws GuzzleException
15
     */
16
    public function request(string $url, array $data): array
17
    {
18
        $baseUrl = 'https://api.kavenegar.com/v1/'.$url;
19
        try {
20
            $client = new Client();
21
            $request = $client->post($baseUrl, ['form_params' => $data]);
22
            $response = [
23
                'status' => true,
24
                'providerResult' => json_decode($request->getBody()->getContents(), true),
25
            ];
26
        } catch (\Exception $e) {
27
            $response = [
28
                'status' => false,
29
                'providerResult' => $e->getMessage(),
30
            ];
31
        }
32
33
        return $response;
34
    }
35
}
36