Conditions | 7 |
Paths | 6 |
Total Lines | 67 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
32 | public static function getLocalFreeBusyMessage($store = false) { |
||
33 | if (!$store) { |
||
34 | error_log("getLocalFreeBusyMessage: store not available"); |
||
35 | |||
36 | return false; |
||
37 | } |
||
38 | |||
39 | // Check for mapi_freebusy_openmsg function, |
||
40 | // If yes then use mapi function to get freebusy message. |
||
41 | if (function_exists('mapi_freebusy_openmsg')) { |
||
42 | return mapi_freebusy_openmsg($store); |
||
43 | } |
||
44 | |||
45 | // Get 'LocalFreeBusy' message from FreeBusy Store |
||
46 | $root = mapi_msgstore_openentry($store); |
||
47 | $storeProps = mapi_getprops($root, [PR_FREEBUSY_ENTRYIDS]); |
||
48 | $localFreeBusyEntryids = $storeProps[PR_FREEBUSY_ENTRYIDS]; |
||
49 | |||
50 | try { |
||
51 | return mapi_msgstore_openentry($store, $localFreeBusyEntryids[self::DELEGATE_PROPERTIES]); |
||
|
|||
52 | } |
||
53 | catch (MAPIException $e) { |
||
54 | // Either user store have malformed entryid in PR_FREEBUSY_ENTRYIDS or |
||
55 | // No message found of given entryid in 'Freebusy Data' folder. |
||
56 | if ($e->getCode() == MAPI_E_NOT_FOUND || $e->getCode() == MAPI_E_INVALID_ENTRYID) { |
||
57 | $freeBusyFolder = mapi_msgstore_openentry($store, $localFreeBusyEntryids[self::FREEBUSYDATA_IPM_SUBTREE]); |
||
58 | $table = mapi_folder_getcontentstable($freeBusyFolder); |
||
59 | mapi_table_restrict( |
||
60 | $table, |
||
61 | [ |
||
62 | RES_CONTENT, |
||
63 | [ |
||
64 | FUZZYLEVEL => FL_PREFIX, |
||
65 | ULPROPTAG => PR_MESSAGE_CLASS, |
||
66 | VALUE => [PR_MESSAGE_CLASS => "IPM.Microsoft.ScheduleData.FreeBusy"], |
||
67 | ], |
||
68 | ] |
||
69 | ); |
||
70 | |||
71 | $items = mapi_table_queryallrows($table, [PR_ENTRYID]); |
||
72 | if (empty($items)) { |
||
73 | // FIXME recreate local freebusy message in 'Freebusy Data' folder. |
||
74 | error_log("Unable to find local free busy message in 'Freebusy Data' folder"); |
||
75 | |||
76 | return false; |
||
77 | } |
||
78 | |||
79 | $localFreeBusyEntryids[1] = $items[0][PR_ENTRYID]; |
||
80 | |||
81 | // Updating the entryid in the PR_FREEBUSY_ENTRYIDS property of user store. |
||
82 | mapi_setprops($root, [PR_FREEBUSY_ENTRYIDS => $localFreeBusyEntryids]); |
||
83 | mapi_savechanges($root); |
||
84 | |||
85 | return mapi_msgstore_openentry($store, $localFreeBusyEntryids[self::DELEGATE_PROPERTIES]); |
||
86 | } |
||
87 | |||
88 | // Ensure to return false if an exception occurs |
||
89 | error_log("getLocalFreeBusyMessage: unhandled MAPIException " . $e->getMessage()); |
||
90 | |||
91 | return false; |
||
92 | |||
93 | } |
||
94 | |||
95 | // Fallback, should not typically reach here. |
||
96 | error_log("getLocalFreeBusyMessage: reached unexpected code path"); |
||
97 | |||
98 | return false; |
||
99 | |||
122 |