Complex classes like EwsConnection 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 EwsConnection, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class EwsConnection |
||
13 | { |
||
14 | /** |
||
15 | * Microsoft Exchange 2007 |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | const VERSION_2007 = 'Exchange2007'; |
||
20 | |||
21 | /** |
||
22 | * Microsoft Exchange 2007 SP1 |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | const VERSION_2007_SP1 = 'Exchange2007_SP1'; |
||
27 | |||
28 | /** |
||
29 | * Microsoft Exchange 2007 SP2 |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | const VERSION_2007_SP2 = 'Exchange2007_SP2'; |
||
34 | |||
35 | /** |
||
36 | * Microsoft Exchange 2007 SP3 |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | const VERSION_2007_SP3 = 'Exchange2007_SP3'; |
||
41 | |||
42 | /** |
||
43 | * Microsoft Exchange 2010 |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | const VERSION_2010 = 'Exchange2010'; |
||
48 | |||
49 | /** |
||
50 | * Microsoft Exchange 2010 SP1 |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | const VERSION_2010_SP1 = 'Exchange2010_SP1'; |
||
55 | |||
56 | /** |
||
57 | * Microsoft Exchange 2010 SP2 |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | const VERSION_2010_SP2 = 'Exchange2010_SP2'; |
||
62 | |||
63 | /** |
||
64 | * Password to use when connecting to the Exchange server. |
||
65 | * |
||
66 | * @var string |
||
67 | */ |
||
68 | protected $password; |
||
69 | |||
70 | /** |
||
71 | * Location of the Exchange server. |
||
72 | * |
||
73 | * @var string |
||
74 | */ |
||
75 | protected $server; |
||
76 | |||
77 | /** |
||
78 | * SOAP client used to make the request |
||
79 | * |
||
80 | * @var ExchangeSoapClient |
||
81 | */ |
||
82 | protected $soap; |
||
83 | |||
84 | /** |
||
85 | * Username to use when connecting to the Exchange server. |
||
86 | * |
||
87 | * @var string |
||
88 | */ |
||
89 | protected $username; |
||
90 | |||
91 | /** |
||
92 | * Exchange impersonation |
||
93 | * |
||
94 | * @var ExchangeImpersonationType |
||
95 | */ |
||
96 | protected $impersonation; |
||
97 | |||
98 | /** |
||
99 | * Miscrosoft Exchange version that we are going to connect to |
||
100 | * |
||
101 | * @var string |
||
102 | * |
||
103 | * @see EwsConnection::VERSION_2007 |
||
104 | * @see EwsConnection::VERSION_2007_SP1 |
||
105 | * @see EwsConnection::VERSION_2010 |
||
106 | * @see EwsConnection::VERSION_2010_SP1 |
||
107 | */ |
||
108 | protected $version; |
||
109 | |||
110 | /** |
||
111 | * Constructor for the \PhpEws\EwsConnection class |
||
112 | * |
||
113 | * @param string $server |
||
114 | * @param string $username |
||
115 | * @param string $password |
||
116 | * @param string $version one of the EwsConnection::VERSION_* constants |
||
117 | */ |
||
118 | public function __construct( |
||
119 | $server = null, |
||
120 | $username = null, |
||
121 | $password = null, |
||
122 | $version = self::VERSION_2007 |
||
123 | ) { |
||
124 | // Set the object properties. |
||
125 | $this->setServer($server); |
||
126 | $this->setUsername($username); |
||
127 | $this->setPassword($password); |
||
128 | $this->setVersion($version); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Returns the SOAP Client that may be used to make calls against the server |
||
133 | * |
||
134 | * @return ExchangeSoapClient |
||
135 | */ |
||
136 | public function getClient() |
||
140 | |||
141 | /** |
||
142 | * Sets the impersonation property |
||
143 | * |
||
144 | * @param ExchangeImpersonationType $impersonation |
||
145 | * |
||
146 | * @return boolean |
||
147 | */ |
||
148 | public function setImpersonation($impersonation) |
||
154 | |||
155 | /** |
||
156 | * Sets the password property |
||
157 | * |
||
158 | * @param string $password |
||
159 | */ |
||
160 | public function setPassword($password) |
||
166 | |||
167 | /** |
||
168 | * Sets the server property |
||
169 | * |
||
170 | * @param string $server |
||
171 | */ |
||
172 | public function setServer($server) |
||
178 | |||
179 | /** |
||
180 | * Sets the user name property |
||
181 | * |
||
182 | * @param string $username |
||
183 | */ |
||
184 | public function setUsername($username) |
||
190 | |||
191 | /** |
||
192 | * Sets the version property |
||
193 | * |
||
194 | * @param string $version |
||
195 | */ |
||
196 | public function setVersion($version) |
||
202 | |||
203 | /** |
||
204 | * Function Description |
||
205 | * |
||
206 | * @param AddDelegateType $request |
||
207 | * @return AddDelegateResponseMessageType |
||
208 | */ |
||
209 | public function AddDelegate($request) |
||
216 | |||
217 | /** |
||
218 | * Function Description |
||
219 | * |
||
220 | * @param ConvertIdType $request |
||
221 | * @return ConvertIdResponseType |
||
222 | */ |
||
223 | public function ConvertId($request) |
||
230 | |||
231 | /** |
||
232 | * Function Description |
||
233 | * |
||
234 | * @param CopyFolderType $request |
||
235 | * @return CopyFolderResponseType |
||
236 | */ |
||
237 | public function CopyFolder($request) |
||
244 | |||
245 | /** |
||
246 | * Function Description |
||
247 | * |
||
248 | * @param CopyItemType $request |
||
249 | * @return CopyItemResponseType |
||
250 | */ |
||
251 | public function CopyItem($request) |
||
258 | |||
259 | /** |
||
260 | * Function Description |
||
261 | * |
||
262 | * @param CreateAttachmentType $request |
||
263 | * @return CreateAttachmentResponseType |
||
264 | */ |
||
265 | public function CreateAttachment($request) |
||
272 | |||
273 | /** |
||
274 | * Function Description |
||
275 | * |
||
276 | * @param CreateFolderType $request |
||
277 | * @return CreateFolderResponseType |
||
278 | */ |
||
279 | public function CreateFolder($request) |
||
286 | |||
287 | /** |
||
288 | * Function Description |
||
289 | * |
||
290 | * @param CreateItemType $request |
||
291 | * @return CreateItemResponseType |
||
292 | */ |
||
293 | public function CreateItem($request) |
||
300 | |||
301 | /** |
||
302 | * Function Description |
||
303 | * |
||
304 | * @param CreateManagedFolderRequestType $request |
||
305 | * @return CreateManagedFolderResponseType |
||
306 | */ |
||
307 | public function CreateManagedFolder($request) |
||
314 | |||
315 | /** |
||
316 | * Function Description |
||
317 | * |
||
318 | * @param DeleteAttachmentType $request |
||
319 | * @return DeleteAttachmentResponseType |
||
320 | */ |
||
321 | public function DeleteAttachment($request) |
||
328 | |||
329 | /** |
||
330 | * Function Description |
||
331 | * |
||
332 | * @param DeleteFolderType $request |
||
333 | * @return DeleteFolderResponseType |
||
334 | */ |
||
335 | public function DeleteFolder($request) |
||
342 | |||
343 | /** |
||
344 | * Function Description |
||
345 | * |
||
346 | * @param DeleteItemType $request |
||
347 | * @return DeleteItemResponseType |
||
348 | */ |
||
349 | public function DeleteItem($request) |
||
356 | |||
357 | /** |
||
358 | * Function Description |
||
359 | * |
||
360 | * @param ExpandDLType $request |
||
361 | * @return ExpandDLResponseType |
||
362 | */ |
||
363 | public function ExpandDL($request) |
||
370 | |||
371 | /** |
||
372 | * Function Description |
||
373 | * |
||
374 | * @param EWS_FindFolderType $request |
||
375 | * @return EWS_FindFolderResponseType |
||
376 | */ |
||
377 | public function FindFolder($request) |
||
384 | |||
385 | /** |
||
386 | * Function Description |
||
387 | * |
||
388 | * @param FindItemType $request |
||
389 | * @return FindItemResponseType |
||
390 | */ |
||
391 | public function FindItem($request) |
||
398 | |||
399 | /** |
||
400 | * Function Description |
||
401 | * |
||
402 | * @param GetAttachmentType $request |
||
403 | * @return GetAttachmentResponseType |
||
404 | */ |
||
405 | public function GetAttachment($request) |
||
412 | |||
413 | /** |
||
414 | * Function Description |
||
415 | * |
||
416 | * @param GetDelegateType $request |
||
417 | * @return GetDelegateResponseMessageType |
||
418 | */ |
||
419 | public function GetDelegate($request) |
||
426 | |||
427 | /** |
||
428 | * Function Description |
||
429 | * |
||
430 | * @param GetEventsType $request |
||
431 | * @return GetEventsResponseType |
||
432 | */ |
||
433 | public function GetEvents($request) |
||
440 | |||
441 | /** |
||
442 | * Function Description |
||
443 | * |
||
444 | * @param GetFolderType $request |
||
445 | * @return GetFolderResponseType |
||
446 | */ |
||
447 | public function GetFolder($request) |
||
454 | |||
455 | /** |
||
456 | * Function Description |
||
457 | * |
||
458 | * @param GetItemType $request |
||
459 | * @return GetItemResponseType |
||
460 | */ |
||
461 | public function GetItem($request) |
||
468 | |||
469 | /** |
||
470 | * Retrieve the timezones supported by the server. |
||
471 | * |
||
472 | * @param GetServerTimeZonesType $request |
||
473 | * @return GetServerTimeZonesResponseType |
||
474 | * |
||
475 | * @since Exchange2010 |
||
476 | */ |
||
477 | public function GetServerTimeZones($request) |
||
484 | |||
485 | /** |
||
486 | * Function Description |
||
487 | * |
||
488 | * @param GetUserAvailabilityRequestType $request |
||
489 | * @return GetUserAvailabilityResponseType |
||
490 | */ |
||
491 | public function GetUserAvailability($request) |
||
498 | |||
499 | /** |
||
500 | * Function Description |
||
501 | * |
||
502 | * @param GetUserOofSettingsRequest $request |
||
503 | * @return GetUserOofSettingsResponse |
||
504 | */ |
||
505 | public function GetUserOofSettings($request) |
||
512 | |||
513 | /** |
||
514 | * Function Description |
||
515 | * |
||
516 | * @param MoveFolderType $request |
||
517 | * @return MoveFolderResponseType |
||
518 | */ |
||
519 | public function MoveFolder($request) |
||
526 | |||
527 | /** |
||
528 | * Function Description |
||
529 | * |
||
530 | * @param MoveItemType $request |
||
531 | * @return MoveItemResponseType |
||
532 | */ |
||
533 | public function MoveItem($request) |
||
540 | |||
541 | /** |
||
542 | * Function Description |
||
543 | * |
||
544 | * @param RemoveDelegateType $request |
||
545 | * @return RemoveDelegateResponseMessageType |
||
546 | */ |
||
547 | public function RemoveDelegate($request) |
||
554 | |||
555 | /** |
||
556 | * Function Description |
||
557 | * |
||
558 | * @param ResolveNamesType $request |
||
559 | * @return ResolveNamesResponseType |
||
560 | */ |
||
561 | public function ResolveNames($request) |
||
568 | |||
569 | /** |
||
570 | * Function Description |
||
571 | * |
||
572 | * @param SendItemType $request |
||
573 | * @return SendItemResponseType |
||
574 | */ |
||
575 | public function SendItem($request) |
||
582 | |||
583 | /** |
||
584 | * Function Description |
||
585 | * |
||
586 | * @param SetUserOofSettingsRequest $request |
||
587 | * @return SetUserOofSettingsResponse |
||
588 | */ |
||
589 | public function SetUserOofSettings($request) |
||
596 | |||
597 | /** |
||
598 | * Function Description |
||
599 | * |
||
600 | * @param SubscribeType $request |
||
601 | * @return SubscribeResponseType |
||
602 | */ |
||
603 | public function Subscribe($request) |
||
610 | |||
611 | /** |
||
612 | * Function Description |
||
613 | * |
||
614 | * @param SyncFolderHierarchyType $request |
||
615 | * @return SyncFolderHierarchyResponseType |
||
616 | */ |
||
617 | public function SyncFolderHierarchy($request) |
||
624 | |||
625 | /** |
||
626 | * Function Description |
||
627 | * |
||
628 | * @param SyncFolderItemsType $request |
||
629 | * @return SyncFolderItemsResponseType |
||
630 | */ |
||
631 | public function SyncFolderItems($request) |
||
638 | |||
639 | /** |
||
640 | * Function Description |
||
641 | * |
||
642 | * @param UnsubscribeType $request |
||
643 | * @return UnsubscribeResponseType |
||
644 | */ |
||
645 | public function Unsubscribe($request) |
||
652 | |||
653 | /** |
||
654 | * Function Description |
||
655 | * |
||
656 | * @param UpdateDelegateType $request |
||
657 | * @return UpdateDelegateResponseMessageType |
||
658 | */ |
||
659 | public function UpdateDelegate($request) |
||
666 | |||
667 | /** |
||
668 | * Function Description |
||
669 | * |
||
670 | * @param UpdateFolderType $request |
||
671 | * @return UpdateFolderResponseType |
||
672 | */ |
||
673 | public function UpdateFolder($request) |
||
680 | |||
681 | /** |
||
682 | * Function Description |
||
683 | * |
||
684 | * @param UpdateItemType $request |
||
685 | * @return UpdateItemResponseType |
||
686 | */ |
||
687 | public function UpdateItem($request) |
||
694 | |||
695 | /** |
||
696 | * Initializes the SoapClient object to make a request |
||
697 | * |
||
698 | * @return ExchangeSoapClient |
||
699 | */ |
||
700 | protected function initializeSoapClient() |
||
715 | |||
716 | /** |
||
717 | * Process a response to verify that it succeeded and take the appropriate |
||
718 | * action |
||
719 | * |
||
720 | * @throws EwsException If the response was not "OK" (200) |
||
721 | * |
||
722 | * @param stdClass $response |
||
723 | * @return \PhpEws\DataType |
||
724 | * |
||
725 | * @todo Map the response to a real object. |
||
726 | */ |
||
727 | protected function processResponse($response) |
||
737 | } |
||
738 |