| Total Complexity | 84 |
| Total Lines | 326 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like TaskItemModule 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 TaskItemModule, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class TaskItemModule extends ItemModule |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Constructor |
||
| 14 | * @param int $id unique id. |
||
| 15 | * @param array $data list of all actions. |
||
| 16 | */ |
||
| 17 | function __construct($id, $data) |
||
| 18 | { |
||
| 19 | parent::__construct($id, $data); |
||
| 20 | |||
| 21 | $this->properties = $GLOBALS["properties"]->getTaskProperties(); |
||
|
|
|||
| 22 | |||
| 23 | $this->plaintext = true; |
||
| 24 | } |
||
| 25 | |||
| 26 | function open($store, $entryid, $action) |
||
| 27 | { |
||
| 28 | $data = array(); |
||
| 29 | |||
| 30 | $message = $GLOBALS['operations']->openMessage($store, $entryid); |
||
| 31 | |||
| 32 | if(empty($message)) { |
||
| 33 | return; |
||
| 34 | } |
||
| 35 | |||
| 36 | // Open embedded message if requested |
||
| 37 | $attachNum = !empty($action['attach_num']) ? $action['attach_num'] : false; |
||
| 38 | if($attachNum) { |
||
| 39 | // get message props of sub message |
||
| 40 | $parentMessage = $message; |
||
| 41 | $message = $GLOBALS['operations']->openMessage($store, $entryid, $attachNum); |
||
| 42 | |||
| 43 | if(empty($message)) { |
||
| 44 | return; |
||
| 45 | } |
||
| 46 | |||
| 47 | $data['item'] = $GLOBALS['operations']->getEmbeddedMessageProps($store, $message, $this->properties, $parentMessage, $attachNum); |
||
| 48 | } else { |
||
| 49 | $data['item'] = $GLOBALS['operations']->getMessageProps($store, $message, $this->properties, $this->plaintext); |
||
| 50 | |||
| 51 | $tr = new TaskRequest($store, $message, $GLOBALS['mapisession']->getSession()); |
||
| 52 | if ($tr->isTaskRequest() || $tr->isTaskRequestResponse()) { |
||
| 53 | $tr->isTaskRequest() ? $tr->processTaskRequest() : $tr->processTaskResponse(); |
||
| 54 | $task = $tr->getAssociatedTask(false); |
||
| 55 | $action["message_action"]["open_task"] = true; |
||
| 56 | $data = $this->getMessageProps($store, $entryid, $action, $task); |
||
| 57 | $data['item']['props']['task_not_found'] = ($task === false); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | $this->addActionData('item', $data); |
||
| 62 | $GLOBALS['bus']->addData($this->getResponseData()); |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Function which used to open and get the all properties of the message. if message_action |
||
| 67 | * "open_task" is true then it will open the associated task of task request and return its data item |
||
| 68 | * else return the task request data item. |
||
| 69 | * |
||
| 70 | * @param object $store MAPI Message Store Object |
||
| 71 | * @param string $entryid entryid of the message |
||
| 72 | * @param object $task associated task of task request |
||
| 73 | * |
||
| 74 | * @return array $data item properties of given message. |
||
| 75 | */ |
||
| 76 | function getMessageProps($store, $entryid, $action, $task) |
||
| 77 | { |
||
| 78 | if(isset($action["message_action"]["open_task"]) && $action["message_action"]["open_task"] && $task !== false) { |
||
| 79 | $taskProps = mapi_getprops($task, array(PR_ENTRYID, PR_PARENT_ENTRYID,PR_STORE_ENTRYID)); |
||
| 80 | $message = $GLOBALS['operations']->openMessage($store, $taskProps[PR_ENTRYID]); |
||
| 81 | } else { |
||
| 82 | $message = $GLOBALS['operations']->openMessage($store, $entryid); |
||
| 83 | } |
||
| 84 | $data['item'] = $GLOBALS['operations']->getMessageProps($store, $message, $this->properties, $this->plaintext); |
||
| 85 | return $data; |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Function which saves an item. |
||
| 90 | * @param object $store MAPI Message Store Object |
||
| 91 | * @param string $parententryid parent entryid of the message |
||
| 92 | * @param array $action the action data, sent by the client |
||
| 93 | * @return boolean true on success or false on failure |
||
| 94 | */ |
||
| 95 | function save($store, $parententryid, $entryid, $action) |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Function which deletes an item. |
||
| 141 | * @param object $store MAPI Message Store Object |
||
| 142 | * @param string $parententryid parent entryid of the message |
||
| 143 | * @param string $entryid entryid of the message |
||
| 144 | * @param array $action the action data, sent by the client |
||
| 145 | * @return boolean true on success or false on failure |
||
| 146 | */ |
||
| 147 | function delete($store, $parententryid, $entryids, $action) |
||
| 167 | } |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Deletes a task. |
||
| 173 | * |
||
| 174 | * deletes occurrence if task is a recurring item. |
||
| 175 | * @param mapistore $store MAPI Message Store Object |
||
| 176 | * @param string $parententryid parent entryid of the messages to be deleted |
||
| 177 | * @param array $entryids a list of entryids which will be deleted |
||
| 178 | * @param boolean $softDelete flag for soft-deleting (when user presses Shift+Del) |
||
| 179 | * @return boolean true if action succeeded, false if not |
||
| 180 | */ |
||
| 181 | function deleteTask($store, $parententryid, $entryids, $action) |
||
| 226 | } |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Save task item. |
||
| 230 | * |
||
| 231 | * just one step more before saving task message that to support recurrence and task request here. We need |
||
| 232 | * to regenerate task if it is recurring and client has changed either set as complete or delete or |
||
| 233 | * given new start or end date. |
||
| 234 | * |
||
| 235 | * @param mapistore $store MAPI store of the message |
||
| 236 | * @param string $parententryid Parent entryid of the message (folder entryid, NOT message entryid) |
||
| 237 | * @param array $action Action array containing XML request |
||
| 238 | * @return array of PR_ENTRYID, PR_PARENT_ENTRYID and PR_STORE_ENTRYID properties of modified item |
||
| 239 | */ |
||
| 240 | function saveTask($store, $parententryid, $entryid, $action) |
||
| 339 |