| Conditions | 37 |
| Paths | > 20000 |
| Total Lines | 180 |
| Code Lines | 101 |
| 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 |
||
| 64 | function edit(array $content=null ,$msg='') |
||
| 65 | { |
||
| 66 | $tmpl = new Etemplate('mail.acl'); |
||
| 67 | if (!is_array($content)) |
||
| 68 | { |
||
| 69 | $acc_id = $_GET['acc_id']?$_GET['acc_id']:$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']; |
||
| 70 | if (isset($_GET['account_id']) && !isset($GLOBALS['egw_info']['user']['apps']['admin'])) |
||
| 71 | { |
||
| 72 | Framework::window_close(lang('Permission denied')); |
||
| 73 | } |
||
| 74 | $account_id = $_GET['account_id']; |
||
| 75 | } |
||
| 76 | else |
||
| 77 | { |
||
| 78 | $acc_id = $content['acc_id']; |
||
| 79 | $account_id = $content['account_id']; |
||
| 80 | } |
||
| 81 | $account = Mail\Account::read($acc_id, $account_id); |
||
| 82 | $this->imap = $account->imapServer(isset($account_id) ? (int)$account_id : false); |
||
| 83 | |||
| 84 | $mailbox = $_GET['mailbox']? base64_decode($_GET['mailbox']): |
||
| 85 | preg_replace("/^".$acc_id."::/",'',$content['mailbox'][0]); |
||
| 86 | if (empty($mailbox)) |
||
| 87 | { |
||
| 88 | $mailbox = $this->imap->isAdminConnection ? $this->imap->getUserMailboxString($account_id) : 'INBOX'; |
||
| 89 | } |
||
| 90 | if (!$this->imap->isAdminConnection) |
||
| 91 | { |
||
| 92 | $tmpl->setElementAttribute('mailbox', 'autocomplete_url', 'mail.mail_compose.ajax_searchFolder'); |
||
| 93 | $tmpl->setElementAttribute('mailbox', 'autocomplete_params', array('mailaccount' => $acc_id)); |
||
| 94 | } |
||
| 95 | else |
||
|
|
|||
| 96 | { |
||
| 97 | //Todo: Implement autocomplete_url function with admin stuffs consideration |
||
| 98 | } |
||
| 99 | // Unset the content if folder is changed, in order to read acl rights for new selected folder |
||
| 100 | if (!is_array($content['button']) && is_array($content['mailbox']) && !is_array($content['grid']['delete'])) unset($content); |
||
| 101 | |||
| 102 | if (!is_array($content)) |
||
| 103 | { |
||
| 104 | if (!empty($mailbox)) |
||
| 105 | { |
||
| 106 | $content['mailbox'] = $mailbox; |
||
| 107 | $acl = (array)$this->retrive_acl($mailbox, $msg); |
||
| 108 | $n = 1; |
||
| 109 | foreach ($acl as $key => $value) |
||
| 110 | { |
||
| 111 | $virtuals = array_pop(array_values((array)$value)); |
||
| 112 | $rights = array_shift(array_values((array)$value)); |
||
| 113 | |||
| 114 | foreach ($rights as $right) |
||
| 115 | { |
||
| 116 | $content['grid'][$n]['acl_'. $right] = true; |
||
| 117 | } |
||
| 118 | $virtualD = array('e','t'); |
||
| 119 | $content['grid'][$n]['acl_c'] = array_diff($virtuals['c'],array_intersect($rights,$virtuals['c']))? false: true; //c=kx more information rfc4314, Obsolote Rights |
||
| 120 | $content['grid'][$n]['acl_d'] = array_diff($virtualD,array_intersect($rights,$virtuals['d']))? false: true; //d=et more information rfc4314, Obsolote Rights |
||
| 121 | |||
| 122 | sort($rights); |
||
| 123 | $acl_abbrvs = implode('',$rights); |
||
| 124 | |||
| 125 | if (array_key_exists($acl_abbrvs, $this->aclRightsAbbrvs)) |
||
| 126 | { |
||
| 127 | $content['grid'][$n]['acl'] = $acl_abbrvs; |
||
| 128 | } |
||
| 129 | else |
||
| 130 | { |
||
| 131 | $content['grid'][$n]['acl'] = 'custom'; |
||
| 132 | } |
||
| 133 | if (($user = $this->imap->getMailBoxAccountId($key))) |
||
| 134 | { |
||
| 135 | $content['grid'][$n++]['acc_id'] = $user; |
||
| 136 | } |
||
| 137 | else |
||
| 138 | { |
||
| 139 | $content['grid'][$n++]['acc_id'] = $key; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | //error_log(__METHOD__."() acl=".array2string($acl).' --> grid='.array2string($content['grid'])); |
||
| 143 | } |
||
| 144 | //Set the acl entry in the last row with lrs as default ACL |
||
| 145 | array_push($content['grid'], array( |
||
| 146 | 'acc_id'=>'', |
||
| 147 | 'acl_l' => true, |
||
| 148 | 'acl_r' => true, |
||
| 149 | 'acl_s' => true)); |
||
| 150 | } |
||
| 151 | else |
||
| 152 | { |
||
| 153 | list($button) = @each($content['button']); |
||
| 154 | if (!empty ($content['grid']['delete'])) |
||
| 155 | { |
||
| 156 | $button = 'delete'; |
||
| 157 | } |
||
| 158 | switch ($button) |
||
| 159 | { |
||
| 160 | case 'save': |
||
| 161 | case 'apply': |
||
| 162 | if ($content) |
||
| 163 | { |
||
| 164 | $validation_err = $this->update_acl($content,$msg); |
||
| 165 | if ($validation_err) |
||
| 166 | { |
||
| 167 | foreach ($validation_err as &$row) |
||
| 168 | { |
||
| 169 | $tmpl->set_validation_error('grid['.$row.']'.'[acc_id]', "You must fill this field!"); |
||
| 170 | } |
||
| 171 | } |
||
| 172 | |||
| 173 | //Add new row at the end |
||
| 174 | if ($content['grid'][count($content['grid'])]['acc_id']) |
||
| 175 | array_push($content['grid'], array('acc_id'=>'')); |
||
| 176 | } |
||
| 177 | else |
||
| 178 | { |
||
| 179 | $msg .= "\n".lang("Error: Could not save ACL").' '.lang("reason!"); |
||
| 180 | } |
||
| 181 | //Send message |
||
| 182 | Framework::message($msg); |
||
| 183 | if ($button == "apply") break; |
||
| 184 | Framework::window_close(); |
||
| 185 | exit; |
||
| 186 | |||
| 187 | case 'delete': |
||
| 188 | $aclRvmCnt = $this->remove_acl($content, $msg); |
||
| 189 | if (is_array($aclRvmCnt)) |
||
| 190 | { |
||
| 191 | $content['grid'] = $aclRvmCnt; |
||
| 192 | } |
||
| 193 | else |
||
| 194 | { |
||
| 195 | error_log(__METHOD__.__LINE__. "()" . "The remove_acl suppose to return an array back, something is wrong there"); |
||
| 196 | } |
||
| 197 | Framework::message($msg); |
||
| 198 | } |
||
| 199 | } |
||
| 200 | $readonlys = $sel_options = array(); |
||
| 201 | $sel_options['acl'] = $this->aclRightsAbbrvs; |
||
| 202 | |||
| 203 | //Make the account owner's fields all readonly as owner has all rights and should not be able to change them |
||
| 204 | foreach($content['grid'] as $key => $fields) |
||
| 205 | { |
||
| 206 | if (self::_extract_acc_id($fields['acc_id']) == $this->imap->acc_imap_username) |
||
| 207 | { |
||
| 208 | foreach (array_keys($fields) as $index) |
||
| 209 | { |
||
| 210 | $readonlys['grid'][$key][$index] = true; |
||
| 211 | } |
||
| 212 | $readonlys['grid']['delete['.$key.']'] = true; |
||
| 213 | $readonlys['grid'][$key]['acl_recursive'] = true; |
||
| 214 | $preserv ['grid'][$key] = $fields; |
||
| 215 | $preserv['grid'][$key]['acl_recursive'] = false; |
||
| 216 | } |
||
| 217 | if (count($content['grid']) != $key) |
||
| 218 | { |
||
| 219 | $preserv ['grid'][$key]['acc_id'] = self::_extract_acc_id($fields['acc_id']); |
||
| 220 | $preserv['grid'][$key]['acl_recursive'] = false; |
||
| 221 | $readonlys['grid'][$key]['acc_id'] = true; |
||
| 222 | } |
||
| 223 | } |
||
| 224 | //Make entry row's delete button readonly |
||
| 225 | $readonlys['grid']['delete['.count($content['grid']).']'] = true; |
||
| 226 | |||
| 227 | $preserv['mailbox'] = $content['mailbox']; |
||
| 228 | $preserv['acc_id'] = $acc_id; |
||
| 229 | $preserv['account_id'] = $account_id; |
||
| 230 | $content['grid']['account_type'] = $this->imap->supportsGroupAcl() ? 'both' : 'accounts'; |
||
| 231 | |||
| 232 | // set a custom autocomplete method for mailbox taglist |
||
| 233 | if ($account_id) |
||
| 234 | { |
||
| 235 | $tmpl->setElementAttribute('mailbox', 'autocomplete_url', __CLASS__.'::ajax_folders'); |
||
| 236 | $tmpl->setElementAttribute('mailbox', 'autocomplete_params', array( |
||
| 237 | 'acc_id' => $acc_id, |
||
| 238 | 'account_id' => $account_id, |
||
| 239 | )); |
||
| 240 | } |
||
| 241 | |||
| 242 | $tmpl->exec('mail.mail_acl.edit', $content, $sel_options, $readonlys, $preserv,2); |
||
| 243 | } |
||
| 244 | |||
| 534 |
This check looks for the
elsebranches ofifstatements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
elsebranches can be removed.could be turned into
This is much more concise to read.