We have detected an error in your notification set-up
(Event-ID dab39dc24f564ec7bd4628d1305fd03c).
Currently, we cannot inform you about inspection progress.
Please check that the user
557058:bca11929-8c2d-43f2-8a82-c5416880d395 still has access to your repository or
update the API account.
Complex classes like Client often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Client, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class Client extends ClientListener implements ClientInterface |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var array |
||
| 28 | */ |
||
| 29 | protected $options = array( |
||
| 30 | 'base_url' => 'https://api.bitbucket.org', |
||
| 31 | 'api_version' => '1.0', |
||
| 32 | 'api_versions' => array('1.0', '2.0'), // supported versions |
||
| 33 | 'format' => 'json', |
||
| 34 | 'formats' => array('json', 'xml'), // supported response formats |
||
| 35 | 'user_agent' => 'bitbucket-api-php/1.1.2 (https://bitbucket.org/gentlero/bitbucket-api)', |
||
| 36 | 'timeout' => 10, |
||
| 37 | 'verify_peer' => true |
||
| 38 | ); |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var BuzzClientInterface |
||
| 42 | */ |
||
| 43 | protected $client; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var RequestInterface |
||
| 47 | */ |
||
| 48 | private $lastRequest; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var MessageInterface |
||
| 52 | */ |
||
| 53 | private $lastResponse; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var MessageInterface |
||
| 57 | */ |
||
| 58 | protected $responseObj; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var RequestInterface |
||
| 62 | */ |
||
| 63 | protected $requestObj; |
||
| 64 | |||
| 65 | 312 | public function __construct(array $options = array(), BuzzClientInterface $client = null) |
|
| 73 | |||
| 74 | /** |
||
| 75 | * {@inheritdoc} |
||
| 76 | */ |
||
| 77 | 8 | public function get($endpoint, $params = array(), $headers = array()) |
|
| 78 | { |
||
| 79 | 8 | if (is_array($params) && count($params) > 0) { |
|
| 80 | 1 | $endpoint .= (strpos($endpoint, '?') === false ? '?' : '&').http_build_query($params, '', '&'); |
|
| 81 | 1 | $params = array(); |
|
| 82 | } |
||
| 83 | |||
| 84 | 8 | return $this->request($endpoint, $params, 'GET', $headers); |
|
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * {@inheritdoc} |
||
| 89 | */ |
||
| 90 | 3 | public function post($endpoint, $params = array(), $headers = array()) |
|
| 94 | |||
| 95 | /** |
||
| 96 | * {@inheritdoc} |
||
| 97 | */ |
||
| 98 | 1 | public function put($endpoint, $params = array(), $headers = array()) |
|
| 102 | |||
| 103 | /** |
||
| 104 | * {@inheritdoc} |
||
| 105 | */ |
||
| 106 | 1 | public function delete($endpoint, $params = array(), $headers = array()) |
|
| 110 | |||
| 111 | /** |
||
| 112 | * {@inheritdoc} |
||
| 113 | */ |
||
| 114 | 16 | public function request($endpoint, $params = array(), $method = 'GET', array $headers = array()) |
|
| 154 | |||
| 155 | /** |
||
| 156 | * @access public |
||
| 157 | * @return BuzzClientInterface |
||
| 158 | */ |
||
| 159 | 1 | public function getClient() |
|
| 163 | |||
| 164 | /** |
||
| 165 | * {@inheritdoc} |
||
| 166 | */ |
||
| 167 | 12 | public function getResponseFormat() |
|
| 171 | |||
| 172 | /** |
||
| 173 | * {@inheritdoc} |
||
| 174 | */ |
||
| 175 | 4 | public function setResponseFormat($format) |
|
| 185 | |||
| 186 | /** |
||
| 187 | * {@inheritdoc} |
||
| 188 | */ |
||
| 189 | 17 | public function getApiVersion() |
|
| 193 | |||
| 194 | /** |
||
| 195 | * {@inheritdoc} |
||
| 196 | */ |
||
| 197 | 111 | public function setApiVersion($version) |
|
| 207 | |||
| 208 | /** |
||
| 209 | * Check if specified API version is the one currently in use. |
||
| 210 | * |
||
| 211 | * @access public |
||
| 212 | * @param float $version |
||
| 213 | * @return bool |
||
| 214 | */ |
||
| 215 | 1 | public function isApiVersion($version) |
|
| 219 | |||
| 220 | /** |
||
| 221 | * {@inheritdoc} |
||
| 222 | */ |
||
| 223 | 16 | public function getApiBaseUrl() |
|
| 227 | |||
| 228 | /** |
||
| 229 | * @access public |
||
| 230 | * @return MessageInterface |
||
| 231 | */ |
||
| 232 | 7 | public function getLastRequest() |
|
| 236 | |||
| 237 | /** |
||
| 238 | * @access public |
||
| 239 | * @return RequestInterface |
||
| 240 | */ |
||
| 241 | 2 | public function getLastResponse() |
|
| 245 | |||
| 246 | /** |
||
| 247 | * @access public |
||
| 248 | * @param MessageInterface $response |
||
| 249 | * @return void |
||
| 250 | */ |
||
| 251 | public function setResponse(MessageInterface $response) |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @access public |
||
| 258 | * @param RequestInterface $request |
||
| 259 | * @return void |
||
| 260 | */ |
||
| 261 | 1 | public function setRequest(RequestInterface $request) |
|
| 265 | |||
| 266 | /** |
||
| 267 | * @access protected |
||
| 268 | * @param string $method |
||
| 269 | * @param string $url |
||
| 270 | * @return RequestInterface |
||
| 271 | */ |
||
| 272 | 15 | protected function createRequest($method, $url) |
|
| 294 | |||
| 295 | /** |
||
| 296 | * Execute all available listeners. |
||
| 297 | * |
||
| 298 | * $when can be: preSend or postSend |
||
| 299 | * |
||
| 300 | * @access protected |
||
| 301 | * @param RequestInterface $request |
||
| 302 | * @param string $when When to execute the listener |
||
| 303 | * @param MessageInterface $response |
||
| 304 | */ |
||
| 305 | 16 | protected function executeListeners(RequestInterface $request, $when = 'preSend', MessageInterface $response = null) |
|
| 330 | } |
||
| 331 |