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 | * @var string |
||
| 71 | */ |
||
| 72 | protected $proxy = ''; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var bool |
||
| 76 | */ |
||
| 77 | protected $debug = false; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var null |
||
| 81 | */ |
||
| 82 | protected $client = null; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var string |
||
| 86 | */ |
||
| 87 | protected $libraryName = 'yandex-php-library'; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @return string |
||
| 91 | */ |
||
| 92 | 12 | public function getUserAgent() |
|
| 93 | { |
||
| 94 | 12 | return $this->libraryName . '/' . Version::$version; |
|
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @param string $accessToken |
||
| 99 | * |
||
| 100 | * @return self |
||
| 101 | */ |
||
| 102 | 85 | public function setAccessToken($accessToken) |
|
| 103 | { |
||
| 104 | 85 | $this->accessToken = $accessToken; |
|
| 105 | |||
| 106 | 85 | return $this; |
|
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @return string |
||
| 111 | */ |
||
| 112 | 15 | public function getAccessToken() |
|
| 116 | |||
| 117 | /** |
||
| 118 | * @param $proxy |
||
| 119 | * @return $this |
||
| 120 | */ |
||
| 121 | public function setProxy($proxy) |
||
| 122 | { |
||
| 123 | $this->proxy = $proxy; |
||
| 124 | |||
| 125 | return $this; |
||
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @return string |
||
| 130 | */ |
||
| 131 | 12 | public function getProxy() |
|
| 135 | |||
| 136 | /** |
||
| 137 | * @param $debug |
||
| 138 | * @return $this |
||
| 139 | */ |
||
| 140 | public function setDebug($debug) |
||
| 141 | { |
||
| 142 | $this->debug = (bool) $debug; |
||
| 143 | |||
| 144 | return $this; |
||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @return bool |
||
| 149 | */ |
||
| 150 | 12 | public function getDebug() |
|
| 154 | |||
| 155 | /** |
||
| 156 | * @param string $serviceDomain |
||
| 157 | * |
||
| 158 | * @return self |
||
| 159 | */ |
||
| 160 | 4 | public function setServiceDomain($serviceDomain) |
|
| 161 | { |
||
| 162 | 4 | $this->serviceDomain = $serviceDomain; |
|
| 163 | |||
| 164 | 4 | return $this; |
|
| 165 | } |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @return string |
||
| 169 | */ |
||
| 170 | 18 | public function getServiceDomain() |
|
| 174 | |||
| 175 | /** |
||
| 176 | * @param string $servicePort |
||
| 177 | * |
||
| 178 | * @return self |
||
| 179 | */ |
||
| 180 | 4 | public function setServicePort($servicePort) |
|
| 181 | { |
||
| 182 | 4 | $this->servicePort = $servicePort; |
|
| 183 | |||
| 184 | 4 | return $this; |
|
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @return string |
||
| 189 | */ |
||
| 190 | 4 | public function getServicePort() |
|
| 194 | |||
| 195 | /** |
||
| 196 | * @param string $serviceScheme |
||
| 197 | * |
||
| 198 | * @return self |
||
| 199 | */ |
||
| 200 | 4 | public function setServiceScheme($serviceScheme = self::HTTPS_SCHEME) |
|
| 201 | { |
||
| 202 | 4 | $this->serviceScheme = $serviceScheme; |
|
| 203 | |||
| 204 | 4 | return $this; |
|
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @return string |
||
| 209 | */ |
||
| 210 | 6 | public function getServiceScheme() |
|
| 214 | |||
| 215 | /** |
||
| 216 | * @param string $resource |
||
| 217 | * @return string |
||
| 218 | */ |
||
| 219 | 16 | public function getServiceUrl($resource = '') |
|
| 223 | |||
| 224 | /** |
||
| 225 | * Check package configuration |
||
| 226 | * |
||
| 227 | * @return boolean |
||
| 228 | */ |
||
| 229 | protected function doCheckSettings() |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @param ClientInterface $client |
||
| 236 | * @return $this |
||
| 237 | */ |
||
| 238 | 1 | protected function setClient(ClientInterface $client) |
|
| 239 | { |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @return ClientInterface |
||
| 247 | */ |
||
| 248 | 13 | View Code Duplication | protected function getClient() |
| 271 | |||
| 272 | /** |
||
| 273 | * Sends a request |
||
| 274 | * |
||
| 275 | * @param string $method HTTP method |
||
| 276 | * @param string|UriInterface $uri URI object or string. |
||
| 277 | * @param array $options Request options to apply. |
||
| 278 | * |
||
| 279 | * @throws Exception\MissedArgumentException |
||
| 280 | * @throws Exception\ProfileNotFoundException |
||
| 281 | * @throws Exception\YandexException |
||
| 282 | * @return Response |
||
| 283 | */ |
||
| 284 | 8 | protected function sendRequest($method, $uri, array $options = []) |
|
| 313 | |||
| 314 | /** |
||
| 315 | * @param $body |
||
| 316 | * @param string $type |
||
| 317 | * @return mixed|\SimpleXMLElement |
||
| 318 | */ |
||
| 319 | 56 | protected function getDecodedBody($body, $type = null) |
|
| 332 | } |
||
| 333 |
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..