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::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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