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 |
||
31 | abstract class AbstractServiceClient extends AbstractPackage |
||
32 | { |
||
33 | /** |
||
34 | * Request schemes constants |
||
35 | */ |
||
36 | const HTTPS_SCHEME = 'https'; |
||
37 | const HTTP_SCHEME = 'http'; |
||
38 | |||
39 | const DECODE_TYPE_JSON = 'json'; |
||
40 | const DECODE_TYPE_XML = 'xml'; |
||
41 | const DECODE_TYPE_DEFAULT = self::DECODE_TYPE_JSON; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $serviceScheme = self::HTTPS_SCHEME; |
||
47 | |||
48 | /** |
||
49 | * Can be HTTP 1.0 or HTTP 1.1 |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $serviceProtocolVersion = '1.1'; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $serviceDomain = ''; |
||
58 | |||
59 | /** |
||
60 | * @var string |
||
61 | */ |
||
62 | protected $servicePort = ''; |
||
63 | |||
64 | /** |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $accessToken = ''; |
||
68 | |||
69 | |||
70 | /** |
||
71 | * @var \DateTime |
||
72 | */ |
||
73 | protected $expiresIn = null; |
||
74 | |||
75 | /** |
||
76 | * @var string |
||
77 | */ |
||
78 | protected $proxy = ''; |
||
79 | |||
80 | /** |
||
81 | * @var bool |
||
82 | */ |
||
83 | protected $debug = false; |
||
84 | |||
85 | /** |
||
86 | * @var null |
||
87 | */ |
||
88 | protected $client = null; |
||
89 | |||
90 | /** |
||
91 | * @var string |
||
92 | */ |
||
93 | protected $libraryName = 'yandex-php-library'; |
||
94 | |||
95 | /** |
||
96 | * @return string |
||
97 | */ |
||
98 | 3 | public function getUserAgent() |
|
102 | |||
103 | /** |
||
104 | * @param string $accessToken |
||
105 | * |
||
106 | * @return self |
||
107 | */ |
||
108 | 147 | public function setAccessToken($accessToken) |
|
114 | |||
115 | /** |
||
116 | * @return string |
||
117 | */ |
||
118 | 46 | public function getAccessToken() |
|
122 | |||
123 | /** |
||
124 | * @param \DateTime $expiresIn |
||
125 | */ |
||
126 | 3 | public function setExpiresIn($expiresIn) |
|
130 | |||
131 | /** |
||
132 | * @return mixed |
||
133 | */ |
||
134 | 2 | public function getExpiresIn() |
|
138 | |||
139 | /** |
||
140 | * @param $proxy |
||
141 | * @return $this |
||
142 | */ |
||
143 | public function setProxy($proxy) |
||
149 | |||
150 | /** |
||
151 | * @return string |
||
152 | */ |
||
153 | 3 | public function getProxy() |
|
157 | |||
158 | /** |
||
159 | * @param $debug |
||
160 | * @return $this |
||
161 | */ |
||
162 | public function setDebug($debug) |
||
168 | |||
169 | /** |
||
170 | * @return bool |
||
171 | */ |
||
172 | 3 | public function getDebug() |
|
176 | |||
177 | /** |
||
178 | * @param string $serviceDomain |
||
179 | * |
||
180 | * @return self |
||
181 | */ |
||
182 | 4 | public function setServiceDomain($serviceDomain) |
|
188 | |||
189 | /** |
||
190 | * @return string |
||
191 | */ |
||
192 | 9 | public function getServiceDomain() |
|
196 | |||
197 | /** |
||
198 | * @param string $servicePort |
||
199 | * |
||
200 | * @return self |
||
201 | */ |
||
202 | 4 | public function setServicePort($servicePort) |
|
208 | |||
209 | /** |
||
210 | * @return string |
||
211 | */ |
||
212 | 4 | public function getServicePort() |
|
216 | |||
217 | /** |
||
218 | * @param string $serviceScheme |
||
219 | * |
||
220 | * @return self |
||
221 | */ |
||
222 | 4 | public function setServiceScheme($serviceScheme = self::HTTPS_SCHEME) |
|
228 | |||
229 | /** |
||
230 | * @return string |
||
231 | */ |
||
232 | 6 | public function getServiceScheme() |
|
236 | |||
237 | /** |
||
238 | * @param string $resource |
||
239 | * @return string |
||
240 | */ |
||
241 | 17 | public function getServiceUrl($resource = '') |
|
245 | |||
246 | /** |
||
247 | * Check package configuration |
||
248 | * |
||
249 | * @return boolean |
||
250 | */ |
||
251 | protected function doCheckSettings() |
||
255 | |||
256 | /** |
||
257 | * @param ClientInterface $client |
||
258 | * @return $this |
||
259 | */ |
||
260 | 2 | protected function setClient(ClientInterface $client) |
|
266 | |||
267 | /** |
||
268 | * @return ClientInterface |
||
269 | */ |
||
270 | 4 | View Code Duplication | protected function getClient() |
293 | |||
294 | /** |
||
295 | * Sends a request |
||
296 | * |
||
297 | * @param string $method HTTP method |
||
298 | * @param string|UriInterface $uri URI object or string. |
||
299 | * @param array $options Request options to apply. |
||
300 | * |
||
301 | * @throws Exception\MissedArgumentException |
||
302 | * @throws Exception\ProfileNotFoundException |
||
303 | * @throws Exception\YandexException |
||
304 | * @return Response |
||
305 | */ |
||
306 | 8 | protected function sendRequest($method, $uri, array $options = []) |
|
335 | |||
336 | /** |
||
337 | * @param $body |
||
338 | * @param string $type |
||
339 | * @return mixed|\SimpleXMLElement |
||
340 | */ |
||
341 | 90 | protected function getDecodedBody($body, $type = null) |
|
354 | } |
||
355 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..