These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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
|
|||
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
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. ![]() |
|||
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 |
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.