| Conditions | 24 |
| Paths | 87 |
| Total Lines | 126 |
| Code Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 50 | public function update($event, $entryid, $props) |
||
| 51 | { |
||
| 52 | switch($event) { |
||
| 53 | case REQUEST_START: |
||
| 54 | $this->reopenStore = false; |
||
| 55 | break; |
||
| 56 | case OBJECT_SAVE: |
||
| 57 | case TABLE_SAVE: |
||
| 58 | case TABLE_DELETE: |
||
| 59 | $data = array(); |
||
| 60 | |||
| 61 | // If no PR_ENTRYID is given, we will settle with PR_PARENT_ENTRYID |
||
| 62 | $folderEntryid = false; |
||
| 63 | if (isset($props[PR_PARENT_ENTRYID])) { |
||
| 64 | $folderEntryid = $props[PR_PARENT_ENTRYID]; |
||
| 65 | } else if(isset($props[PR_ENTRYID])) { |
||
| 66 | $folderEntryid = $props[PR_ENTRYID]; |
||
| 67 | } |
||
| 68 | |||
| 69 | // We won't send notifiers for changes to the todolist folder, since there is nothing to |
||
| 70 | // be updated by the client. |
||
| 71 | $entryIdUtil = new EntryId(); |
||
| 72 | if ( $entryIdUtil->compareEntryIds(bin2hex($folderEntryid), bin2hex(TodoList::getEntryId())) ){ |
||
| 73 | return; |
||
| 74 | } |
||
| 75 | |||
| 76 | if (!isset($props[PR_STORE_ENTRYID]) && !$folderEntryid) { |
||
| 77 | break; |
||
| 78 | } |
||
| 79 | |||
| 80 | $store = $GLOBALS["mapisession"]->openMessageStore($props[PR_STORE_ENTRYID]); |
||
| 81 | |||
| 82 | $folder = mapi_msgstore_openentry($store, $folderEntryid); |
||
| 83 | if ($folder) { |
||
| 84 | $properties = $GLOBALS["properties"]->getFolderListProperties(); |
||
| 85 | $folderProps = mapi_getprops($folder, $properties); |
||
| 86 | |||
| 87 | // If this folder belongs to Favorites folder,then change PARENT_ENTRYID manually. |
||
| 88 | if ($GLOBALS["entryid"]->isFavoriteFolder($folderProps[PR_ENTRYID])) { |
||
| 89 | $storeProps = mapi_getprops($store, array(PR_IPM_FAVORITES_ENTRYID)); |
||
| 90 | |||
| 91 | if (isset($storeProps[PR_IPM_FAVORITES_ENTRYID])) { |
||
| 92 | $favFolder = mapi_msgstore_openentry($store, $storeProps[PR_IPM_FAVORITES_ENTRYID]); |
||
| 93 | $favHierarchyTable = mapi_folder_gethierarchytable($favFolder, MAPI_DEFERRED_ERRORS); |
||
| 94 | $folders = mapi_table_queryallrows($favHierarchyTable, array(PR_DISPLAY_NAME, PR_STORE_ENTRYID), |
||
| 95 | array(RES_PROPERTY, |
||
| 96 | array( |
||
| 97 | RELOP => RELOP_EQ, |
||
| 98 | ULPROPTAG => PR_ENTRYID, |
||
| 99 | VALUE => array( |
||
| 100 | PR_ENTRYID => $folderProps[PR_ENTRYID] |
||
| 101 | ) |
||
| 102 | ) |
||
| 103 | ) |
||
| 104 | ); |
||
| 105 | |||
| 106 | if (!empty($folders)) { |
||
| 107 | // Update folderProps to properties of folder which is under 'FAVORITES' |
||
| 108 | $folderProps[PR_DISPLAY_NAME] = $folders[0][PR_DISPLAY_NAME]; |
||
| 109 | $folderProps[PR_PARENT_ENTRYID] = $storeProps[PR_IPM_FAVORITES_ENTRYID]; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | $data[] = $GLOBALS["operations"]->setFolder($folderProps); |
||
| 115 | } |
||
| 116 | |||
| 117 | $this->addNotificationActionData("folders", array( "item" => $data )); |
||
| 118 | $GLOBALS["bus"]->addData($this->createNotificationResponseData()); |
||
| 119 | |||
| 120 | // data is changed in store so message size will be updated so reopen store to get correct data |
||
| 121 | $this->reopenStore = true; |
||
| 122 | break; |
||
| 123 | case OBJECT_DELETE: |
||
| 124 | if (isset($props[PR_ENTRYID]) && isset($props[PR_PARENT_ENTRYID])) { |
||
| 125 | $data = array(); |
||
| 126 | $data["folderdelete"] = 1; |
||
| 127 | $data["entryid"] = bin2hex($props[PR_ENTRYID]); |
||
| 128 | $data["parent_entryid"] = bin2hex($props[PR_PARENT_ENTRYID]); |
||
| 129 | $data["store_entryid"] = bin2hex($props[PR_STORE_ENTRYID]); |
||
| 130 | |||
| 131 | $this->addNotificationActionData("folders", array( "item" => $data )); |
||
| 132 | $GLOBALS["bus"]->addData($this->createNotificationResponseData()); |
||
| 133 | |||
| 134 | // data is changed in store so message size will be updated so reopen store to get correct data |
||
| 135 | $this->reopenStore = true; |
||
| 136 | } |
||
| 137 | break; |
||
| 138 | case REQUEST_END: |
||
| 139 | if($this->reopenStore) { |
||
| 140 | // @FIXME this actually very heavy operation for performance point of view |
||
| 141 | // we need to remove this in future |
||
| 142 | $store = $GLOBALS["mapisession"]->getDefaultMessageStore(true); |
||
| 143 | } else { |
||
| 144 | $store = $GLOBALS["mapisession"]->getDefaultMessageStore(); |
||
| 145 | } |
||
| 146 | |||
| 147 | // reset flag for further use |
||
| 148 | $this->reopenStore = false; |
||
| 149 | |||
| 150 | // Send notification for any changes in store's properties |
||
| 151 | if($store) { |
||
| 152 | $storeProps = mapi_getprops($store, array(PR_ENTRYID, PR_STORE_ENTRYID, PR_MDB_PROVIDER, PR_OBJECT_TYPE, PR_QUOTA_WARNING_THRESHOLD, PR_QUOTA_SEND_THRESHOLD, PR_QUOTA_RECEIVE_THRESHOLD, PR_MESSAGE_SIZE_EXTENDED)); |
||
| 153 | |||
| 154 | $storeSize = round($storeProps[PR_MESSAGE_SIZE_EXTENDED]/1024); |
||
| 155 | |||
| 156 | // Check whether size of the store is changed, if it is changed then |
||
| 157 | // send latest store size and quota information to client-side. |
||
| 158 | if($this->storeSize != $storeSize) { |
||
| 159 | $data = array(); |
||
| 160 | $data["props"] = array(); |
||
| 161 | $data["store_entryid"] = bin2hex($storeProps[PR_STORE_ENTRYID]); |
||
| 162 | $data["props"]["object_type"] = $storeProps[PR_OBJECT_TYPE]; |
||
| 163 | $data["props"]["store_size"] = $storeSize; |
||
| 164 | $data["props"]["quota_warning"] = isset($storeProps[PR_QUOTA_WARNING_THRESHOLD]) ? $storeProps[PR_QUOTA_WARNING_THRESHOLD] : 0; |
||
| 165 | $data["props"]["quota_soft"] = isset($storeProps[PR_QUOTA_SEND_THRESHOLD]) ? $storeProps[PR_QUOTA_SEND_THRESHOLD] : 0; |
||
| 166 | $data["props"]["quota_hard"] = isset($storeProps[PR_QUOTA_RECEIVE_THRESHOLD]) ? $storeProps[PR_QUOTA_RECEIVE_THRESHOLD] : 0; |
||
| 167 | |||
| 168 | $this->addNotificationActionData("stores", array( "item" => array($data) )); |
||
| 169 | $GLOBALS["bus"]->addData($this->createNotificationResponseData()); |
||
| 170 | |||
| 171 | // assign size for next checking |
||
| 172 | $this->storeSize = $storeSize; |
||
| 173 | } |
||
| 174 | } |
||
| 175 | break; |
||
| 176 | } |
||
| 180 |
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.