| Conditions | 6 |
| Paths | 17 |
| Total Lines | 70 |
| Code Lines | 33 |
| 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 |
||
| 62 | public function createConnector( |
||
| 63 | $provider, |
||
| 64 | TokenStorageInterface $storage, |
||
| 65 | array $options = [], |
||
| 66 | $id = null, |
||
| 67 | ClientInterface $http_client = null, |
||
| 68 | ServiceFactory $service_factory = null, |
||
| 69 | CredentialsInterface $credentials = null |
||
| 70 | ) { |
||
| 71 | // Only allow configured providers. |
||
| 72 | if (!array_key_exists($provider, $this->config['providers'])) { |
||
| 73 | throw new InvalidProviderException($provider); |
||
| 74 | } |
||
| 75 | |||
| 76 | // Default to CurlClient (why isn't this the default? :( ) |
||
| 77 | if (is_null($http_client)) { |
||
| 78 | $http_client = new CurlClient; |
||
| 79 | } |
||
| 80 | |||
| 81 | // Just if we want to be lazy and not pass this as an argument. |
||
| 82 | if (is_null($service_factory)) { |
||
| 83 | $service_factory = new ServiceFactory; |
||
| 84 | } |
||
| 85 | |||
| 86 | // Simplify config access for this provider. |
||
| 87 | $config = $this->getFlatConfig($provider); |
||
| 88 | |||
| 89 | |||
| 90 | // We're already getting the credentials via $this->config, we might not |
||
| 91 | // want to always pass them as an argument. |
||
| 92 | if (is_null($credentials)) { |
||
| 93 | $credentials = new Credentials( |
||
| 94 | $config['consumer_key'], |
||
| 95 | $config['consumer_secret'], |
||
| 96 | $config['callback'] |
||
| 97 | ); |
||
| 98 | } |
||
| 99 | |||
| 100 | // Let's make use of CurlClient. |
||
| 101 | $service_factory->setHttpClient($http_client); |
||
| 102 | |||
| 103 | // Temporary (or so I hope) hack to overcome PHPoAuthLib not being ready |
||
| 104 | // for Facebook's Graph API 1.0 deprecation. |
||
| 105 | |||
| 106 | // If this is Facebook, let's specify we want API v2.2 |
||
| 107 | // $api_version = null; |
||
| 108 | // if (strtolower($provider) == 'facebook') { |
||
| 109 | // $api_version = '2.2'; |
||
| 110 | // } |
||
| 111 | $uri = null; |
||
| 112 | if (in_array($provider, ['Facebook', 'FacebookGroup', 'FacebookPage'])) { |
||
| 113 | $uri = new Uri('https://graph.facebook.com/v2.8/'); |
||
| 114 | } |
||
| 115 | |||
| 116 | // Finally, create the service already! |
||
| 117 | $service = $service_factory->createService( |
||
| 118 | $config['service'], |
||
| 119 | $credentials, |
||
| 120 | $storage, |
||
| 121 | $config['scopes'], |
||
| 122 | $uri |
||
| 123 | //$api_version |
||
| 124 | ); |
||
| 125 | |||
| 126 | |||
| 127 | $connector_class = '\\Borfast\\Socializr\\Connectors\\'.$provider; |
||
| 128 | $connector = new $connector_class($config, $service, $options, $id); |
||
| 129 | |||
| 130 | return $connector; |
||
| 131 | } |
||
| 132 | |||
| 172 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.