Conditions | 10 |
Paths | 9 |
Total Lines | 34 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
47 | public static function createHttpClient($handler) |
||
48 | { |
||
49 | if (!$handler) { |
||
50 | return self::detectDefaultClient(); |
||
51 | } |
||
52 | |||
53 | if ($handler instanceof FacebookHttpClientInterface) { |
||
54 | return $handler; |
||
55 | } |
||
56 | |||
57 | if ('stream' === $handler) { |
||
58 | return new FacebookStreamHttpClient(); |
||
59 | } |
||
60 | if ('curl' === $handler) { |
||
61 | if (!extension_loaded('curl')) { |
||
62 | throw new Exception('The cURL extension must be loaded in order to use the "curl" handler.'); |
||
63 | } |
||
64 | |||
65 | return new FacebookCurlHttpClient(); |
||
66 | } |
||
67 | |||
68 | if ('guzzle' === $handler && !class_exists('GuzzleHttp\Client')) { |
||
69 | throw new Exception('The Guzzle HTTP client must be included in order to use the "guzzle" handler.'); |
||
70 | } |
||
71 | |||
72 | if ($handler instanceof Client) { |
||
73 | return new FacebookGuzzleHttpClient($handler); |
||
74 | } |
||
75 | if ('guzzle' === $handler) { |
||
76 | return new FacebookGuzzleHttpClient(); |
||
77 | } |
||
78 | |||
79 | throw new InvalidArgumentException('The http client handler must be set to "curl", "stream", "guzzle", be an instance of GuzzleHttp\Client or an instance of Facebook\HttpClients\FacebookHttpClientInterface'); |
||
80 | } |
||
81 | |||
100 |