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.

FetchAllPlans::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
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
class FetchAllPlans extends AbstractFetchAllPlans
12
{
13
    const ALL_PLANS_RELATIVE_LINK = "/plan?merchantId=:m&apiKey=:key";
14
15
    protected $baseUrl;
16
17
    protected $apiKeys;
18
19 4
    public function __construct(string $baseUrl, array $apiKeys)
20
    {
21 4
        $this->apiKeys = $apiKeys;
22 4
        $this->baseUrl = $baseUrl;
23 4
    }
24
25
    /**
26
     * @return mixed
27
     * @throws \Gbowo\Exception\InvalidHttpResponseException if the response status code is not 200
28
     */
29 4
    public function handle()
30
    {
31 4
        $link = $this->baseUrl . str_replace(
32 4
            ":m", $this->apiKeys['merchantId'], self::ALL_PLANS_RELATIVE_LINK
33
        );
34
35 4
        $link = str_replace(":key", $this->apiKeys['apiKey'], $link);
36
37
        /**
38
         * @var ResponseInterface $response
39
         */
40 4
        $response = $this->adapter->getHttpClient()
41 4
            ->get($link);
42
43 4
        if ($response->getStatusCode() !== 200) {
44 1
            throw InvalidHttpResponseException::createFromResponse($response);
45
        }
46
47 3
        return json_decode($response->getBody(), true);
48
    }
49
}
50