These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | |||
4 | namespace Gbowo\Adapter\Amplifypay\Plugin; |
||
5 | |||
6 | use Gbowo\Plugin\AbstractFetchPlan; |
||
7 | use function GuzzleHttp\json_decode; |
||
8 | use Psr\Http\Message\ResponseInterface; |
||
9 | use Gbowo\Exception\InvalidHttpResponseException; |
||
10 | |||
11 | class FetchPlan extends AbstractFetchPlan |
||
12 | { |
||
13 | |||
14 | protected $baseUrl; |
||
15 | |||
16 | protected $apiKeys; |
||
17 | |||
18 | const FETCH_PLAN_RELATIVE_LINK = "/plan"; |
||
19 | |||
20 | public function __construct(string $baseUrl, array $apiKeys) |
||
21 | { |
||
22 | $this->baseUrl = $baseUrl; |
||
23 | $this->apiKeys= $apiKeys; |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * @param array ...$args |
||
28 | * @return mixed |
||
29 | * @throws \Gbowo\Exception\InvalidHttpResponseException if the response code is not 200 |
||
30 | */ |
||
31 | View Code Duplication | public function handle(...$args) |
|
0 ignored issues
–
show
|
|||
32 | { |
||
33 | |||
34 | $link = $this->baseUrl.self::FETCH_PLAN_RELATIVE_LINK."?PlanId={$args[0]}"; |
||
35 | |||
36 | /** |
||
37 | * @var ResponseInterface $response |
||
38 | */ |
||
39 | $response = $this->adapter->getHttpClient() |
||
40 | ->get($link); |
||
41 | |||
42 | if (200 !== $response->getStatusCode()) { |
||
43 | throw new InvalidHttpResponseException( |
||
44 | "Expected 200. Got {$response->getStatusCode()}" |
||
45 | ); |
||
46 | } |
||
47 | |||
48 | return json_decode($response->getBody(), true); |
||
49 | } |
||
50 | } |
||
51 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.