Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
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) |
|
31 | |||
32 | 19 | View Code Duplication | public function getProfile(ProfileQuery $profileQuery): KvkPaginatorInterface |
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 |
47 | |||
48 | 1 | View Code Duplication | public function getPreviousPage(KvkPaginatorInterface $kvkPaginator): KvkPaginatorInterface |
55 | |||
56 | 19 | private function decodeJsonToArray(string $json): array |
|
60 | } |
||
61 |