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 |
||
21 | class WebmasterClient extends AbstractServiceClient |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * @var string $serviceDomain |
||
26 | */ |
||
27 | protected $serviceDomain = 'webmaster.yandex.ru/api/v2'; |
||
28 | |||
29 | /** |
||
30 | * WebmasterClient constructor. |
||
31 | * |
||
32 | * @param string $token |
||
33 | * @param ClientInterface|null $client |
||
34 | */ |
||
35 | public function __construct($token = '', ClientInterface $client = null) |
||
42 | |||
43 | /** |
||
44 | * @see https://tech.yandex.ru/webmaster/doc/dg/reference/hosts-docpage/ |
||
45 | * |
||
46 | * @return Hosts |
||
47 | */ |
||
48 | public function getHosts() |
||
57 | |||
58 | /** |
||
59 | * @see https://tech.yandex.ru/webmaster/doc/dg/reference/hosts-stats-docpage/ |
||
60 | * |
||
61 | * @param $id |
||
62 | * @return Host |
||
63 | */ |
||
64 | public function getHostStats($id) |
||
73 | |||
74 | |||
75 | /** |
||
76 | * @see https://tech.yandex.ru/webmaster/doc/dg/reference/hosts-verify-docpage/ |
||
77 | * |
||
78 | * @param string|int $hostId |
||
79 | * @return Host |
||
80 | */ |
||
81 | public function getHostVerify($hostId) |
||
90 | |||
91 | /** |
||
92 | * @param string $resource |
||
93 | * @return string |
||
94 | */ |
||
95 | public function getServiceUrl($resource = '') |
||
99 | |||
100 | /** |
||
101 | * @param string $method |
||
102 | * @param \Psr\Http\Message\UriInterface|string $uri |
||
103 | * @param array $options |
||
104 | * @return \Psr\Http\Message\ResponseInterface |
||
105 | * @throws MissedArgumentException |
||
106 | * @throws ProfileNotFoundException |
||
107 | * @throws YandexException |
||
108 | */ |
||
109 | View Code Duplication | protected function sendRequest($method, $uri, array $options = []) |
|
139 | |||
140 | /** |
||
141 | * @param string $resource |
||
142 | * @return mixed|\SimpleXMLIterator |
||
143 | */ |
||
144 | public function sendGetRequest($resource = '') |
||
160 | } |
||
161 |
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.