Failed Conditions
Pull Request — master (#8)
by Laurens
02:21
created

Client   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 48
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getEndpoint() 0 7 1
A getUrl() 0 4 1
A getJson() 0 4 1
A get() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Werkspot\KvkApi\Http\Adapter\Guzzle;
6
7
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
8
use GuzzleHttp\Exception\RequestException;
9
use GuzzleHttp\TransferStats;
10
use Psr\Http\Message\ResponseInterface;
11
use Werkspot\KvkApi\Client\Search\QueryInterface;
12
use Werkspot\KvkApi\Http\Adapter\Guzzle\Exception\Handler;
13
use Werkspot\KvkApi\Http\ClientInterface;
14
use Werkspot\KvkApi\Http\Endpoint\MapperInterface;
15
16
final class Client implements ClientInterface
17
{
18
    /**
19
     * @var GuzzleClientInterface
20
     */
21
    private $guzzleClient;
22
23
    /**
24
     * @var MapperInterface
25
     */
26
    private $endpointMapper;
27
28 22
    public function __construct(
29
        GuzzleClientInterface $guzzleClient,
30
        MapperInterface $urlMapper
31
    ) {
32 22
        $this->guzzleClient = $guzzleClient;
33 22
        $this->endpointMapper = $urlMapper;
34 22
    }
35
36 19
    public function getEndpoint(string $endpoint, QueryInterface $searchQuery): ResponseInterface
37
    {
38 19
        return $this->get(
39 19
            $this->endpointMapper->map($endpoint),
40 19
            ['query' => $searchQuery->get()]
41
        );
42
    }
43
44 2
    public function getUrl(string $url): ResponseInterface
45
    {
46 2
        return $this->get($url);
47
    }
48
49 17
    public function getJson(ResponseInterface $response): string
50
    {
51 17
        return $response->getBody()->getContents();
52
    }
53
54 21
    private function get(string $url, ?array $options = [])
55
    {
56
        //var_dump($this->guzzleClient->get($url, $options));
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
57
        try {
58 21
            return $this->guzzleClient->get($url, $options);
59 3
        } catch (RequestException $exception) {
60 3
            Handler::handleRequestException($exception);
61
        }
62
    }
63
}
64