GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 65dc27...4e2c47 )
by Lanre
05:32
created

FetchAllPlans   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 46
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 21 2
1
<?php
2
3
4
namespace Gbowo\Adapter\Amplifypay\Plugin;
5
6
use function GuzzleHttp\json_decode;
7
use Gbowo\Plugin\AbstractFetchAllPlans;
8
use Psr\Http\Message\ResponseInterface;
9
use Gbowo\Exception\InvalidHttpResponseException;
10
11
/**
12
 * @author Lanre Adelowo <[email protected]>
13
 * Class FetchAllPlans
14
 * @package Gbowo\Adapter\Amplifypay\Plugin
15
 */
16
class FetchAllPlans extends AbstractFetchAllPlans
17
{
18
19
    const ALL_PLANS_RELATIVE_LINK = "/plan?merchantId=:m&apiKey=:key";
20
21
    /**
22
     * @var string
23
     */
24
    protected $baseUrl;
25
    /**
26
     * @var array
27
     */
28
    protected $apiKeys;
29
30 4
    public function __construct(string $baseUrl, array $apiKeys)
31
    {
32 4
        $this->apiKeys = $apiKeys;
33 4
        $this->baseUrl = $baseUrl;
34 4
    }
35
36
    /**
37
     * @return mixed
38
     * @throws \Gbowo\Exception\InvalidHttpResponseException if the response status code is not 200
39
     */
40 4
    public function handle()
41
    {
42
43 4
        $link = $this->baseUrl. str_replace(":m",$this->apiKeys['merchantId'],self::ALL_PLANS_RELATIVE_LINK);
44
45 4
        $link = str_replace(":key", $this->apiKeys['apiKey'], $link);
46
47
        /**
48
         * @var ResponseInterface $response
49
         */
50 4
        $response = $this->adapter->getHttpClient()
51 4
            ->get($link);
52
53 4
        if (200 !== $response->getStatusCode()) {
54 1
            throw new InvalidHttpResponseException(
55 1
                "Expected 200. Got{$response->getStatusCode()} instead"
56
            );
57
        }
58
59 3
        return json_decode($response->getBody(), true);
60
    }
61
}
62