Passed
Push — main ( 5dbf08...9589c4 )
by Brian
02:38
created

Authorization::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Bmatovu\AirtelMoney\Products;
4
5
use GuzzleHttp\ClientInterface;
6
use Illuminate\Container\Container;
7
use Illuminate\Contracts\Config\Repository;
8
9
class Authorization
10
{
11
    protected ClientInterface $http;
12
13
    protected Repository $config;
14
15 1
    public function __construct(ClientInterface $http)
16
    {
17 1
        $this->http = $http;
18 1
        $this->config = Container::getInstance()->make('config');
19
    }
20
21
    /**
22
     * @return array<string, mixed>
23
     *
24
     * @throws \GuzzleHttp\Exception\TransferException
25
     */
26 1
    public function getToken(): array
27
    {
28 1
        $authUri = $this->config->get('airtel-money.authorization.token_uri');
29
30 1
        $response = $this->http->request('POST', $authUri, [
31 1
            'json' => [
32 1
                'client_id' => $this->config->get('airtel-money.client_id'),
33 1
                'client_secret' => $this->config->get('airtel-money.client_secret'),
34 1
                'grant_type' => 'client_credentials',
35 1
            ],
36 1
        ]);
37
38 1
        return json_decode((string) $response->getBody(), true);
39
    }
40
}
41