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

KvkClient::getProfile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Werkspot\KvkApi;
6
7
use Werkspot\KvkApi\Client\KvkPaginator;
8
use Werkspot\KvkApi\Client\KvkPaginatorInterface;
9
use Werkspot\KvkApi\Client\Factory\KvkPaginatorFactoryInterface;
10
use Werkspot\KvkApi\Client\Search\ProfileQuery;
11
use Werkspot\KvkApi\Http\ClientInterface;
12
use Werkspot\KvkApi\Http\Endpoint\MapperInterface;
13
14
final class KvkClient
15
{
16
    /**
17
     * @var ClientInterface
18
     */
19
    private $httpClient;
20
21
    /**
22
     * @var KvkPaginatorFactoryInterface
23
     */
24
    private $profileResponseFactory;
25
26 21
    public function __construct(ClientInterface $httpClient, KvkPaginatorFactoryInterface $profileResponseFactory)
27
    {
28 21
        $this->httpClient = $httpClient;
29 21
        $this->profileResponseFactory = $profileResponseFactory;
30 21
    }
31
32 19
    public function getProfile(ProfileQuery $profileQuery): KvkPaginator
33
    {
34 19
        $json = $this->httpClient->getJson($this->httpClient->getEndpoint(MapperInterface::PROFILE, $profileQuery));
35 17
        $data = $this->decodeJsonToArray($json);
36
37 17
        return $this->profileResponseFactory->fromProfileData($data);
38
    }
39
40 1 View Code Duplication
    public function getNextPage(KvkPaginatorInterface $kvkPaginator): KvkPaginatorInterface
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
41
    {
42 1
        $json = $this->httpClient->getJson($this->httpClient->getUrl($kvkPaginator->getNextUrl()));
43 1
        $data = $this->decodeJsonToArray($json);
44
45 1
        return $this->profileResponseFactory->fromProfileData($data);
46
    }
47
48 1 View Code Duplication
    public function getPreviousPage(KvkPaginatorInterface $kvkPaginator): KvkPaginatorInterface
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
49
    {
50 1
        $json = $this->httpClient->getJson($this->httpClient->getUrl($kvkPaginator->getPreviousUrl()));
51 1
        $data = $this->decodeJsonToArray($json);
52
53 1
        return $this->profileResponseFactory->fromProfileData($data);
54
    }
55
56
    /**
57
     * @param $json
58
     * @return mixed
59
     */
60 19
    private function decodeJsonToArray($json)
61
    {
62 19
        return json_decode($json, true)['data'];
63
    }
64
}
65