Conditions | 11 |
Paths | 78 |
Total Lines | 41 |
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 |
||
72 | public function __construct(array $config = []) |
||
73 | { |
||
74 | $appId = isset($config['app_id']) ? $config['app_id'] : getenv(static::APP_ID_ENV_NAME); |
||
75 | if (!$appId) { |
||
76 | throw new MailxpertSDKException( |
||
77 | 'Required "app_id" key not supplied in config and could not find fallback environment variable "'.static::APP_ID_ENV_NAME.'"' |
||
78 | ); |
||
79 | } |
||
80 | |||
81 | $appSecret = isset($config['app_secret']) ? $config['app_secret'] : getenv(static::APP_SECRET_ENV_NAME); |
||
82 | if (!$appSecret) { |
||
83 | throw new MailxpertSDKException( |
||
84 | 'Required "app_secret" key not supplied in config and could not find fallback environment variable "'.static::APP_SECRET_ENV_NAME.'"' |
||
85 | ); |
||
86 | } |
||
87 | |||
88 | $this->app = new MailxpertApp($appId, $appSecret); |
||
89 | |||
90 | if (isset($config['api_base_url'])) { |
||
91 | $this->apiBaseUrl = $config['api_base_url']; |
||
92 | } |
||
93 | |||
94 | $httpClientHandler = null; |
||
95 | if (isset($config['http_client'])) { |
||
96 | $httpClientHandler = $config['http_client']; |
||
97 | |||
98 | if (!$httpClientHandler instanceof MailxpertHttpClientInterface) { |
||
99 | throw new MailxpertSDKException('Config "http_client" should be an instance of MailxpertHttpClientInterface'); |
||
100 | } |
||
101 | } |
||
102 | |||
103 | $this->client = new MailxpertClient($httpClientHandler, $this->apiBaseUrl); |
||
104 | |||
105 | if (isset($config['oauth_base_url'])) { |
||
106 | $this->oauthBaseUrl = $config['oauth_base_url']; |
||
107 | } |
||
108 | |||
109 | if (isset($config['access_token']) && $config['access_token'] instanceof AccessToken) { |
||
110 | $this->accessToken = $config['access_token']; |
||
111 | } |
||
112 | } |
||
113 | |||
200 |