| Conditions | 10 |
| Paths | 9 |
| Total Lines | 33 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 26 | public static function createHttpClient($handler) |
||
| 27 | { |
||
| 28 | if (!$handler) { |
||
| 29 | return self::detectDefaultClient(); |
||
| 30 | } |
||
| 31 | |||
| 32 | if ($handler instanceof InstagramHttpClientInterface) { |
||
| 33 | return $handler; |
||
| 34 | } |
||
| 35 | |||
| 36 | if ('stream' === $handler) { |
||
| 37 | return new InstagramStreamHttpClient(); |
||
| 38 | } |
||
| 39 | if ('curl' === $handler) { |
||
| 40 | if (!extension_loaded('curl')) { |
||
| 41 | throw new Exception('The cURL extension must be loaded in order to use the "curl" handler.'); |
||
| 42 | } |
||
| 43 | |||
| 44 | return new InstagramCurlHttpClient(); |
||
| 45 | } |
||
| 46 | |||
| 47 | if ('guzzle' === $handler && !class_exists('GuzzleHttp\Client')) { |
||
| 48 | throw new Exception('The Guzzle HTTP client must be included in order to use the "guzzle" handler.'); |
||
| 49 | } |
||
| 50 | |||
| 51 | if ($handler instanceof Client) { |
||
| 52 | return new InstagramGuzzleHttpClient($handler); |
||
| 53 | } |
||
| 54 | if ('guzzle' === $handler) { |
||
| 55 | return new InstagramGuzzleHttpClient(); |
||
| 56 | } |
||
| 57 | |||
| 58 | throw new InvalidArgumentException('The http client handler must be set to "curl", "stream", "guzzle", be an instance of GuzzleHttp\Client or an instance of Instagram\HttpClients\InstagramHttpClientInterface'); |
||
| 59 | } |
||
| 79 |