Authentication   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 30
rs 10
ccs 13
cts 13
cp 1
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getToken() 0 13 1
A __construct() 0 4 1
1
<?php
2
3
namespace Bmatovu\AirtelMoney;
4
5
use GuzzleHttp\ClientInterface;
6
use Illuminate\Container\Container;
7
use Illuminate\Contracts\Config\Repository;
8
9
class Authentication
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.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