| Total Complexity | 40 |
| Total Lines | 184 |
| Duplicated Lines | 0 % |
| Changes | 5 | ||
| Bugs | 1 | Features | 0 |
Complex classes like OutOfOfficeSettingsModule 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.
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 OutOfOfficeSettingsModule, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 6 | class OutOfOfficeSettingsModule extends Module { |
||
| 7 | /** |
||
| 8 | * Constructor. |
||
| 9 | * |
||
| 10 | * @param int $id unique id |
||
| 11 | * @param array $data list of all actions |
||
| 12 | */ |
||
| 13 | public function __construct($id, $data) { |
||
| 14 | parent::__construct($id, $data); |
||
| 15 | |||
| 16 | $this->properties = $GLOBALS["properties"]->getOutOfOfficeProperties(); |
||
|
|
|||
| 17 | } |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Executes all the actions in the $data variable. |
||
| 21 | */ |
||
| 22 | public function execute() { |
||
| 23 | foreach ($this->data as $actionType => $action) { |
||
| 24 | if (isset($actionType)) { |
||
| 25 | try { |
||
| 26 | switch ($actionType) { |
||
| 27 | case "list" : |
||
| 28 | $this->getOofSettings(); |
||
| 29 | break; |
||
| 30 | |||
| 31 | case "save" : |
||
| 32 | $this->saveOofSettings($action); |
||
| 33 | break; |
||
| 34 | |||
| 35 | default: |
||
| 36 | $this->handleUnknownActionType($actionType); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | catch (SettingsException $e) { |
||
| 40 | $this->processException($e, $actionType); |
||
| 41 | } |
||
| 42 | catch (MAPIException $e) { |
||
| 43 | $this->processException($e, $actionType); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Read 'out of office' settings from PR_EC_OUTOFOFFICE_*. |
||
| 51 | * |
||
| 52 | * Internal function to retrieve the 'out of office' settings from the store, these settings are normal properties on the store |
||
| 53 | */ |
||
| 54 | public function getOofSettings() { |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Function returns array of user stores who has given 'Owner' permission to logged in user. |
||
| 112 | * Internal function to retrieve the shared stores with 'owner' permission. |
||
| 113 | * |
||
| 114 | * @return {Array} array of user stores who has given 'owner' permission |
||
| 115 | */ |
||
| 116 | public function getOwnerPermissionStores() { |
||
| 117 | $stores = $GLOBALS['mapisession']->getOtherUserStore(); |
||
| 118 | |||
| 119 | // $sharedOwnerStores array will contains store of users who has given 'owner' permission. |
||
| 120 | // Or store of users which can be fully accessible by default user in case of 'Admin User'. |
||
| 121 | $sharedOwnerStores = []; |
||
| 122 | |||
| 123 | foreach ($stores as $storeEntryId => $storeObj) { |
||
| 124 | $subTree = mapi_getprops($storeObj, [PR_IPM_SUBTREE_ENTRYID]); |
||
| 125 | |||
| 126 | try { |
||
| 127 | $subtreeObj = mapi_msgstore_openentry($storeObj, $subTree[PR_IPM_SUBTREE_ENTRYID]); |
||
| 128 | } |
||
| 129 | catch (MAPIException $e) { |
||
| 130 | // we don't have rights to open folder, so don't include User's store. |
||
| 131 | if ($e->getCode() === MAPI_E_NO_ACCESS) { |
||
| 132 | continue; |
||
| 133 | } |
||
| 134 | |||
| 135 | // rethrow other errors |
||
| 136 | throw $e; |
||
| 137 | } |
||
| 138 | |||
| 139 | $permission = mapi_getprops($subtreeObj, [PR_RIGHTS]); |
||
| 140 | $hasSufficientPermission = $permission[PR_RIGHTS] & ecRightsSecretary === ecRightsSecretary; |
||
| 141 | |||
| 142 | // If User store's IPM subtree has rights higher than 'secretary' then include that User's store. |
||
| 143 | if ($hasSufficientPermission) { |
||
| 144 | $sharedOwnerStores[$storeEntryId] = $storeObj; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | return $sharedOwnerStores; |
||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Internal function to save the 'out of office' settings to the correct properties on the store. |
||
| 153 | * On success function will send 'success' feedback to user. |
||
| 154 | * |
||
| 155 | * Writes some properties to the PR_EC_OUTOFOFFICE_* properties |
||
| 156 | * |
||
| 157 | * @param array $action the action data, sent by the client |
||
| 158 | */ |
||
| 159 | public function saveOofSettings($action) { |
||
| 190 | } |
||
| 191 | } |
||
| 192 |