Complex classes like ExchangeWebServices 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 ExchangeWebServices, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 86 | class ExchangeWebServices |
||
| 87 | { |
||
| 88 | const VERSION_2007 = 'Exchange2007'; |
||
| 89 | |||
| 90 | const VERSION_2007_SP1 = 'Exchange2007_SP1'; |
||
| 91 | |||
| 92 | const VERSION_2010 = 'Exchange2010'; |
||
| 93 | |||
| 94 | const VERSION_2010_SP1 = 'Exchange2010_SP1'; |
||
| 95 | |||
| 96 | const VERSION_2010_SP2 = 'Exchange2010_SP2'; |
||
| 97 | |||
| 98 | const VERSION_2013 = 'Exchange2013'; |
||
| 99 | |||
| 100 | const VERSION_2013_SP1 = 'Exchange2013_SP1'; |
||
| 101 | |||
| 102 | const VERSION_2016 = 'Exchange2016'; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Password to use when connecting to the Exchange server. |
||
| 106 | * |
||
| 107 | * @var string |
||
| 108 | */ |
||
| 109 | protected $password = null; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Location of the Exchange server. |
||
| 113 | * |
||
| 114 | * @var string |
||
| 115 | */ |
||
| 116 | protected $server = null; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * SOAP client used to make the request |
||
| 120 | * |
||
| 121 | * @var NTLMSoapClient |
||
| 122 | */ |
||
| 123 | protected $soap = null; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Username to use when connecting to the Exchange server. |
||
| 127 | * |
||
| 128 | * @var string |
||
| 129 | */ |
||
| 130 | protected $username = null; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @var EmailAddressType |
||
| 134 | */ |
||
| 135 | protected $primarySmtpMailbox = null; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @var Callable[] |
||
| 139 | */ |
||
| 140 | protected static $middlewareStack = false; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * A setting to check whether or not responses should be drilled down before being |
||
| 144 | * returned. Setting this to false |
||
| 145 | * will return the raw responses without any filtering |
||
| 146 | * |
||
| 147 | * @var bool |
||
| 148 | */ |
||
| 149 | protected $drillDownResponses = true; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Miscrosoft Exchange version that we are going to connect to |
||
| 153 | * |
||
| 154 | * @var string |
||
| 155 | */ |
||
| 156 | protected $version = null; |
||
| 157 | |||
| 158 | protected $options = null; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * The timezone for the client |
||
| 162 | * |
||
| 163 | * @var bool |
||
| 164 | */ |
||
| 165 | protected $timezone = false; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @return EmailAddressType |
||
| 169 | */ |
||
| 170 | 28 | public function getPrimarySmtpMailbox() |
|
| 174 | |||
| 175 | 1 | public function getPrimarySmtpEmailAddress() |
|
| 183 | |||
| 184 | 2 | public function setPrimarySmtpEmailAddress($emailAddress) |
|
| 192 | |||
| 193 | /** |
||
| 194 | * @param boolean $timezone |
||
| 195 | */ |
||
| 196 | public function setTimezone($timezone) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @return string |
||
| 203 | */ |
||
| 204 | public function getVersion() |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @return string |
||
| 211 | */ |
||
| 212 | public function getServer() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Constructor for the ExchangeWebServices class |
||
| 219 | * |
||
| 220 | * @param string $server |
||
| 221 | * @param string $username |
||
| 222 | * @param string $password |
||
| 223 | * @param array $options |
||
| 224 | */ |
||
| 225 | 37 | protected function __construct($server = null, $username = null, $password = null, $options = array()) |
|
| 237 | |||
| 238 | 35 | public static function fromUsernameAndPassword($server, $username, $password, $options) |
|
| 246 | |||
| 247 | 1 | public static function fromCallbackToken($server, $token, $options) |
|
| 255 | |||
| 256 | 1 | public static function fromCustomAuthentication($server, $authentication, $options) |
|
| 264 | |||
| 265 | 37 | protected function createClient($server, $auth, $options) |
|
| 299 | |||
| 300 | /** |
||
| 301 | * @codeCoverageIgnore |
||
| 302 | * |
||
| 303 | * @param $name |
||
| 304 | * @param $arguments |
||
| 305 | * @return Type |
||
| 306 | * @throws \garethp\ews\API\Exception |
||
| 307 | */ |
||
| 308 | public function __call($name, $arguments) |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Returns the SOAP Client that may be used to make calls against the server |
||
| 318 | * |
||
| 319 | * @return NTLMSoapClient |
||
| 320 | */ |
||
| 321 | 33 | public function getClient() |
|
| 325 | |||
| 326 | /** |
||
| 327 | * Cleans the server URL for usage |
||
| 328 | * |
||
| 329 | * @param $server |
||
| 330 | * @return string |
||
| 331 | */ |
||
| 332 | 44 | public function cleanServerUrl($server) |
|
| 353 | |||
| 354 | /** |
||
| 355 | * Process a response to verify that it succeeded and take the appropriate |
||
| 356 | * action |
||
| 357 | * |
||
| 358 | * @param \garethp\ews\API\Message\BaseResponseMessageType $response |
||
| 359 | * @return Type[] |
||
| 360 | * @throws \garethp\ews\API\Exception |
||
| 361 | */ |
||
| 362 | 30 | protected function processResponse($response) |
|
| 381 | |||
| 382 | /** |
||
| 383 | * @param $response |
||
| 384 | * @return array |
||
| 385 | * @throws \garethp\ews\API\Exception |
||
| 386 | */ |
||
| 387 | 30 | public static function drillDownResponseLevels($response) |
|
| 408 | |||
| 409 | /** |
||
| 410 | * @param $response |
||
| 411 | * @return array |
||
| 412 | * @throws ExchangeException |
||
| 413 | */ |
||
| 414 | 30 | protected static function getItemsFromResponse($response) |
|
| 436 | |||
| 437 | /** |
||
| 438 | * @param Message\BaseResponseMessageType $response |
||
| 439 | * @param $code |
||
| 440 | * @throws ExchangeException |
||
| 441 | * @throws NoResponseReturnedException |
||
| 442 | * @throws ServiceUnavailableException |
||
| 443 | * @throws UnauthorizedException |
||
| 444 | */ |
||
| 445 | 30 | protected function handleNonSuccessfulResponses($response, $code) |
|
| 466 | |||
| 467 | 37 | protected function buildMiddlewareStack() |
|
| 490 | |||
| 491 | /** |
||
| 492 | * @param array $middlewareStack |
||
| 493 | * @param MiddlewareRequest $request |
||
| 494 | * @return MiddlewareResponse |
||
| 495 | */ |
||
| 496 | 30 | protected function executeMiddlewareStack(array $middlewareStack, MiddlewareRequest $request) |
|
| 522 | } |
||
| 523 |