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