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