Total Complexity | 77 |
Total Lines | 340 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
8 | class TaskItemModule extends ItemModule { |
||
9 | /** |
||
10 | * Constructor. |
||
11 | * |
||
12 | * @param int $id unique id |
||
13 | * @param array $data list of all actions |
||
14 | */ |
||
15 | public function __construct($id, $data) { |
||
21 | } |
||
22 | |||
23 | #[Override] |
||
24 | public function open($store, $entryid, $action) { |
||
25 | $data = []; |
||
26 | |||
27 | $message = $GLOBALS['operations']->openMessage($store, $entryid); |
||
28 | |||
29 | if (empty($message)) { |
||
30 | return; |
||
31 | } |
||
32 | |||
33 | // Open embedded message if requested |
||
34 | $attachNum = !empty($action['attach_num']) ? $action['attach_num'] : false; |
||
35 | if ($attachNum) { |
||
36 | // get message props of sub message |
||
37 | $parentMessage = $message; |
||
38 | $message = $GLOBALS['operations']->openMessage($store, $entryid, $attachNum); |
||
39 | |||
40 | if (empty($message)) { |
||
41 | return; |
||
42 | } |
||
43 | |||
44 | $data['item'] = $GLOBALS['operations']->getEmbeddedMessageProps($store, $message, $this->properties, $parentMessage, $attachNum); |
||
45 | } |
||
46 | else { |
||
47 | $data['item'] = $GLOBALS['operations']->getMessageProps($store, $message, $this->properties, $this->plaintext); |
||
48 | |||
49 | $tr = new TaskRequest($store, $message, $GLOBALS['mapisession']->getSession()); |
||
|
|||
50 | if ($tr->isTaskRequest() || $tr->isTaskRequestResponse()) { |
||
51 | $tr->isTaskRequest() ? $tr->processTaskRequest() : $tr->processTaskResponse(); |
||
52 | $task = $tr->getAssociatedTask(false); |
||
53 | $action["message_action"]["open_task"] = true; |
||
54 | $data = $this->getMessageProps($store, $entryid, $action, $task); |
||
55 | $data['item']['props']['task_not_found'] = ($task === false); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | $this->addActionData('item', $data); |
||
60 | $GLOBALS['bus']->addData($this->getResponseData()); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Function which used to open and get the all properties of the message. if message_action |
||
65 | * "open_task" is true then it will open the associated task of task request and return its data item |
||
66 | * else return the task request data item. |
||
67 | * |
||
68 | * @param object $store MAPI Message Store Object |
||
69 | * @param string $entryid entryid of the message |
||
70 | * @param object $task associated task of task request |
||
71 | * @param mixed $action |
||
72 | * |
||
73 | * @return array $data item properties of given message |
||
74 | */ |
||
75 | public function getMessageProps($store, $entryid, $action, $task) { |
||
76 | if (isset($action["message_action"]["open_task"]) && $action["message_action"]["open_task"] && $task !== false) { |
||
77 | $taskProps = mapi_getprops($task, [PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID]); |
||
78 | $message = $GLOBALS['operations']->openMessage($store, $taskProps[PR_ENTRYID]); |
||
79 | } |
||
80 | else { |
||
81 | $message = $GLOBALS['operations']->openMessage($store, $entryid); |
||
82 | } |
||
83 | $data['item'] = $GLOBALS['operations']->getMessageProps($store, $message, $this->properties, $this->plaintext); |
||
84 | |||
85 | return $data; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Function which saves an item. |
||
90 | * |
||
91 | * @param object $store MAPI Message Store Object |
||
92 | * @param string $parententryid parent entryid of the message |
||
93 | * @param array $action the action data, sent by the client |
||
94 | * @param mixed $entryid |
||
95 | */ |
||
96 | #[Override] |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Function which deletes an item. |
||
143 | * |
||
144 | * @param object $store MAPI Message Store Object |
||
145 | * @param string $parententryid parent entryid of the message |
||
146 | * @param mixed $entryids |
||
147 | * @param array $action the action data, sent by the client |
||
148 | */ |
||
149 | #[Override] |
||
170 | } |
||
171 | } |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * Deletes a task. |
||
176 | * |
||
177 | * deletes occurrence if task is a recurring item. |
||
178 | * |
||
179 | * @param mapistore $store MAPI Message Store Object |
||
180 | * @param string $parententryid parent entryid of the messages to be deleted |
||
181 | * @param array $entryids a list of entryids which will be deleted |
||
182 | * @param mixed $action |
||
183 | * |
||
184 | * @return bool true if action succeeded, false if not |
||
185 | */ |
||
186 | public function deleteTask($store, $parententryid, $entryids, $action) { |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * Save task item. |
||
237 | * |
||
238 | * just one step more before saving task message that to support recurrence and task request here. We need |
||
239 | * to regenerate task if it is recurring and client has changed either set as complete or delete or |
||
240 | * given new start or end date. |
||
241 | * |
||
242 | * @param mapistore $store MAPI store of the message |
||
243 | * @param string $parententryid Parent entryid of the message (folder entryid, NOT message entryid) |
||
244 | * @param array $action Action array containing XML request |
||
245 | * @param mixed $entryid |
||
246 | * |
||
247 | * @return array of PR_ENTRYID, PR_PARENT_ENTRYID and PR_STORE_ENTRYID properties of modified item |
||
248 | */ |
||
249 | public function saveTask($store, $parententryid, $entryid, $action) { |
||
350 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths