| Conditions | 22 |
| Paths | 2779 |
| Total Lines | 177 |
| Code Lines | 93 |
| 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 |
||
| 32 | #[Override] |
||
| 33 | public function open($store, $entryid, $action) { |
||
| 34 | if ($entryid) { |
||
| 35 | $data = []; |
||
| 36 | |||
| 37 | try { |
||
| 38 | $abentry = mapi_ab_openentry($GLOBALS["mapisession"]->getAddressbook(false, true), $entryid); |
||
| 39 | } |
||
| 40 | catch (MAPIException $e) { |
||
|
|
|||
| 41 | // If the item not found in addressbook, it might be possible that |
||
| 42 | // this particular item was added by setup-contact-provider mechanism. |
||
| 43 | // Let us try to get that particular contact item in respective user store. |
||
| 44 | // @Fixme: After implementation of KC-350 this extra handling can be removed. |
||
| 45 | if ($e->getCode() == MAPI_E_NOT_FOUND || $e->getCode() == MAPI_E_INVALID_PARAMETER) { |
||
| 46 | if ($GLOBALS['entryid']->hasNoMuid(bin2hex($entryid))) { |
||
| 47 | $entryid = substr($entryid, 0, -1); |
||
| 48 | } |
||
| 49 | else { |
||
| 50 | // unwrap ab entry id |
||
| 51 | $entryid = substr($entryid, 28); |
||
| 52 | } |
||
| 53 | |||
| 54 | try { |
||
| 55 | $contactItem = $GLOBALS['operations']->openMessage($GLOBALS['mapisession']->getDefaultMessageStore(), $entryid); |
||
| 56 | } |
||
| 57 | catch (MAPIException $me) { |
||
| 58 | if (!empty($action['store_entryid'])) { |
||
| 59 | $e->setHandled(); |
||
| 60 | $me->setHandled(); |
||
| 61 | $userStore = $GLOBALS['mapisession']->openMessageStore(hex2bin((string) $action['store_entryid'])); |
||
| 62 | $contactItem = $GLOBALS['operations']->openMessage($userStore, $entryid); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | finally { |
||
| 66 | if (isset($contactItem) && $contactItem != false) { |
||
| 67 | // Get necessary property from respective contact item |
||
| 68 | $contactItemProps = mapi_getprops($contactItem, [PR_GIVEN_NAME, PR_DISPLAY_NAME, PR_TITLE, PR_COMPANY_NAME]); |
||
| 69 | |||
| 70 | // Use the data retrieved from contact item to prepare response |
||
| 71 | // as similar as it seems like an addressbook item. |
||
| 72 | $data['props'] = [ |
||
| 73 | 'object_type' => MAPI_MAILUSER, |
||
| 74 | 'given_name' => $contactItemProps[PR_GIVEN_NAME], |
||
| 75 | 'display_name' => $contactItemProps[PR_DISPLAY_NAME], |
||
| 76 | 'title' => $contactItemProps[PR_TITLE], |
||
| 77 | 'company_name' => $contactItemProps[PR_COMPANY_NAME], |
||
| 78 | ]; |
||
| 79 | $data['entryid'] = bin2hex($entryid); |
||
| 80 | |||
| 81 | $this->addActionData("item", $data); |
||
| 82 | $GLOBALS["bus"]->addData($this->getResponseData()); |
||
| 83 | |||
| 84 | return; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | if (mapi_last_hresult() == NOERROR && $abentry) { |
||
| 91 | $objecttypeprop = mapi_getprops($abentry, [PR_OBJECT_TYPE]); |
||
| 92 | |||
| 93 | if (isset($objecttypeprop[PR_OBJECT_TYPE])) { |
||
| 94 | // Get the properties for a MAILUSER object and process those MAILUSER specific props that require some more actions |
||
| 95 | if ($objecttypeprop[PR_OBJECT_TYPE] == MAPI_MAILUSER) { |
||
| 96 | $messageprops = mapi_getprops($abentry, $this->userDetailProperties); |
||
| 97 | |||
| 98 | $props = Conversion::mapMAPI2XML($this->userDetailProperties, $messageprops); |
||
| 99 | |||
| 100 | if (isset($messageprops[PR_EMS_AB_THUMBNAIL_PHOTO])) { |
||
| 101 | $props['props']['ems_ab_thumbnail_photo'] = $GLOBALS['operations']->compressedImage($messageprops[PR_EMS_AB_THUMBNAIL_PHOTO]); |
||
| 102 | } |
||
| 103 | |||
| 104 | // Get the properties of the manager |
||
| 105 | $managerProps = $this->getManagerDetails($messageprops); |
||
| 106 | if ($managerProps !== false) { |
||
| 107 | $props['ems_ab_manager'] = [ |
||
| 108 | 'item' => $managerProps, |
||
| 109 | ]; |
||
| 110 | } |
||
| 111 | |||
| 112 | $homePhoneNumbers = $this->getHomePhoneNumbers($messageprops); |
||
| 113 | if (!empty($homePhoneNumbers)) { |
||
| 114 | // Add the list of home2_telephone_number_mv in the correct format to $props list to be send to the client |
||
| 115 | $props['home2_telephone_numbers'] = [ |
||
| 116 | 'item' => $homePhoneNumbers, |
||
| 117 | ]; |
||
| 118 | } |
||
| 119 | |||
| 120 | $businessPhoneNumbers = $this->getBusinessPhoneNumbers($messageprops); |
||
| 121 | if (!empty($businessPhoneNumbers)) { |
||
| 122 | // Add the list of business2_telephone_number_mv in the correct format to $props list to be send to the client |
||
| 123 | $props['business2_telephone_numbers'] = [ |
||
| 124 | 'item' => $businessPhoneNumbers, |
||
| 125 | ]; |
||
| 126 | } |
||
| 127 | |||
| 128 | // Get the properties of the "direct reports" |
||
| 129 | $directReportsList = $this->getDirectReportsDetails($messageprops); |
||
| 130 | if (!empty($directReportsList)) { |
||
| 131 | // Add the list of proxy_addresses in the correct format to the $props list to be send to the client. |
||
| 132 | $props['ems_ab_reports'] = [ |
||
| 133 | 'item' => $directReportsList, |
||
| 134 | ]; |
||
| 135 | } |
||
| 136 | |||
| 137 | // Get the properties for a DISTLIST object and process those DISTLIST specific props that require some more actions |
||
| 138 | } |
||
| 139 | else { |
||
| 140 | $messageprops = mapi_getprops($abentry, $this->groupDetailProperties); |
||
| 141 | $props = Conversion::mapMAPI2XML($this->groupDetailProperties, $messageprops); |
||
| 142 | |||
| 143 | // Get the properties of the owner |
||
| 144 | $ownerProps = $this->getOwnerDetails($messageprops); |
||
| 145 | if ($ownerProps !== false) { |
||
| 146 | // We can use the same properties as we use for the manager in a MAILUSER |
||
| 147 | $props['ems_ab_owner'] = [ |
||
| 148 | 'item' => $ownerProps, |
||
| 149 | ]; |
||
| 150 | } |
||
| 151 | |||
| 152 | // Get the list of members for this DISTLSIT |
||
| 153 | $props['members'] = [ |
||
| 154 | 'item' => $this->getMembersDetails($abentry), |
||
| 155 | ]; |
||
| 156 | } |
||
| 157 | |||
| 158 | // Get the proxy addresses list, this property exists in both MAILUSER and DISTLIST |
||
| 159 | $proxyAddresses = $this->getProxyAddressesDetails($messageprops); |
||
| 160 | // Remove the MV-flagged property |
||
| 161 | if (!empty($proxyAddresses)) { |
||
| 162 | // Add the list of proxy_addresses in the correct format to the $props list to be send to the client. |
||
| 163 | $props['ems_ab_proxy_addresses'] = [ |
||
| 164 | 'item' => $proxyAddresses, |
||
| 165 | ]; |
||
| 166 | } |
||
| 167 | |||
| 168 | // Get the properties of the group membership, this property exists in both MAILUSER and DISTLIST |
||
| 169 | $memberOfList = $this->getMemberOfDetails($messageprops); |
||
| 170 | if (!empty($memberOfList)) { |
||
| 171 | // Add the list of proxy_addresses in the correct format to the $props list to be send to the client. |
||
| 172 | $props['ems_ab_is_member_of_dl'] = [ |
||
| 173 | 'item' => $memberOfList, |
||
| 174 | ]; |
||
| 175 | } |
||
| 176 | |||
| 177 | // Remove the MV-flagged properties and also its single valued counterpart |
||
| 178 | unset($props['props']['ems_ab_is_member_of_dl'], $props['props']['business2_telephone_number_mv'], $props['props']['business2_telephone_number'], $props['props']['home2_telephone_number_mv'], $props['props']['home2_telephone_number'], $props['props']['ems_ab_proxy_addresses'], $props['props']['ems_ab_reports_mv'], $props['props']['ems_ab_reports'], $props['props']['ems_ab_owner'], $props['props']['ems_ab_manager']); |
||
| 179 | |||
| 180 | // Allowing to hook in and add more properties |
||
| 181 | $GLOBALS['PluginManager']->triggerHook("server.module.addressbookitemmodule.open.props", [ |
||
| 182 | 'moduleObject' => &$this, |
||
| 183 | 'abentry' => $abentry, |
||
| 184 | 'object_type' => $objecttypeprop[PR_OBJECT_TYPE], |
||
| 185 | 'messageprops' => $messageprops, |
||
| 186 | 'props' => &$props, |
||
| 187 | ]); |
||
| 188 | |||
| 189 | $data["item"] = $props; |
||
| 190 | $this->addActionData("item", $data); |
||
| 191 | } |
||
| 192 | else { |
||
| 193 | // Handling error: not able to handle this type of object |
||
| 194 | $data["error"] = []; |
||
| 195 | $data["error"]["message"] = _("Could not handle this type of object."); |
||
| 196 | $this->addActionData("error", $data); |
||
| 197 | } |
||
| 198 | } |
||
| 199 | else { |
||
| 200 | // Handle not being able to open the object |
||
| 201 | $data["error"] = []; |
||
| 202 | $data["error"]["hresult"] = mapi_last_hresult(); |
||
| 203 | $data["error"]["hresult_name"] = get_mapi_error_name(mapi_last_hresult()); |
||
| 204 | $data["error"]["message"] = _("Could not open this object."); |
||
| 205 | $this->addActionData("error", $data); |
||
| 206 | } |
||
| 207 | |||
| 208 | $GLOBALS["bus"]->addData($this->getResponseData()); |
||
| 209 | } |
||
| 428 |
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