| Conditions | 7 |
| Paths | 6 |
| Total Lines | 60 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 31 | public static function getLocalFreeBusyMessage(mixed $store = false): mixed { |
||
| 32 | if (!$store) { |
||
| 33 | error_log("getLocalFreeBusyMessage: store not available"); |
||
| 34 | |||
| 35 | return false; |
||
| 36 | } |
||
| 37 | |||
| 38 | // Check for mapi_freebusy_openmsg function, |
||
| 39 | // If yes then use mapi function to get freebusy message. |
||
| 40 | if (function_exists('mapi_freebusy_openmsg')) { |
||
| 41 | return mapi_freebusy_openmsg($store); |
||
| 42 | } |
||
| 43 | |||
| 44 | // Get 'LocalFreeBusy' message from FreeBusy Store |
||
| 45 | $root = mapi_msgstore_openentry($store); |
||
| 46 | $storeProps = mapi_getprops($root, [PR_FREEBUSY_ENTRYIDS]); |
||
| 47 | $localFreeBusyEntryids = $storeProps[PR_FREEBUSY_ENTRYIDS]; |
||
| 48 | |||
| 49 | try { |
||
| 50 | return mapi_msgstore_openentry($store, $localFreeBusyEntryids[self::DELEGATE_PROPERTIES]); |
||
|
|
|||
| 51 | } |
||
| 52 | catch (MAPIException $e) { |
||
| 53 | // Either user store have malformed entryid in PR_FREEBUSY_ENTRYIDS or |
||
| 54 | // No message found of given entryid in 'Freebusy Data' folder. |
||
| 55 | if ($e->getCode() === MAPI_E_NOT_FOUND || $e->getCode() === MAPI_E_INVALID_ENTRYID) { |
||
| 56 | $freeBusyFolder = mapi_msgstore_openentry($store, $localFreeBusyEntryids[self::FREEBUSYDATA_IPM_SUBTREE]); |
||
| 57 | $table = mapi_folder_getcontentstable($freeBusyFolder); |
||
| 58 | mapi_table_restrict( |
||
| 59 | $table, |
||
| 60 | [ |
||
| 61 | RES_CONTENT, |
||
| 62 | [ |
||
| 63 | FUZZYLEVEL => FL_PREFIX, |
||
| 64 | ULPROPTAG => PR_MESSAGE_CLASS, |
||
| 65 | VALUE => [PR_MESSAGE_CLASS => "IPM.Microsoft.ScheduleData.FreeBusy"], |
||
| 66 | ], |
||
| 67 | ] |
||
| 68 | ); |
||
| 69 | |||
| 70 | $items = mapi_table_queryallrows($table, [PR_ENTRYID]); |
||
| 71 | if (empty($items)) { |
||
| 72 | // FIXME recreate local freebusy message in 'Freebusy Data' folder. |
||
| 73 | error_log("Unable to find local free busy message in 'Freebusy Data' folder"); |
||
| 74 | |||
| 75 | return false; |
||
| 76 | } |
||
| 77 | |||
| 78 | $localFreeBusyEntryids[1] = $items[0][PR_ENTRYID]; |
||
| 79 | |||
| 80 | // Updating the entryid in the PR_FREEBUSY_ENTRYIDS property of user store. |
||
| 81 | mapi_setprops($root, [PR_FREEBUSY_ENTRYIDS => $localFreeBusyEntryids]); |
||
| 82 | mapi_savechanges($root); |
||
| 83 | |||
| 84 | return mapi_msgstore_openentry($store, $localFreeBusyEntryids[self::DELEGATE_PROPERTIES]); |
||
| 85 | } |
||
| 86 | |||
| 87 | // Ensure to return false if an exception occurs |
||
| 88 | error_log("getLocalFreeBusyMessage: unhandled MAPIException " . $e->getMessage()); |
||
| 89 | |||
| 90 | return false; |
||
| 91 | } |
||
| 112 |