| Conditions | 11 |
| Paths | 60 |
| Total Lines | 75 |
| Code Lines | 38 |
| Lines | 4 |
| Ratio | 5.33 % |
| 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 |
||
| 33 | public function beforeSendToClient($cname, array $expand=null) |
||
| 34 | { |
||
| 35 | |||
| 36 | Framework::includeJS('.','et2_widget_owner','calendar'); |
||
| 37 | Framework::includeCSS('calendar','calendar'); |
||
| 38 | |||
| 39 | $bo = new calendar_bo(); |
||
| 40 | |||
| 41 | $form_name = self::form_name($cname, $this->id, $expand); |
||
| 42 | |||
| 43 | $value =& self::get_array(self::$request->content, $form_name); |
||
| 44 | |||
| 45 | View Code Duplication | if (!is_array(self::$request->sel_options[$form_name])) |
|
| 46 | { |
||
| 47 | self::$request->sel_options[$form_name] = array(); |
||
| 48 | } |
||
| 49 | $sel_options =& self::$request->sel_options[$form_name]; |
||
| 50 | |||
| 51 | // Get user accounts, formatted nicely for grouping and matching |
||
| 52 | // the ajax call calendar_uiforms->ajax_owner() - users first |
||
| 53 | $accounts = array(); |
||
| 54 | $list = array('accounts', 'owngroups'); |
||
| 55 | foreach($list as $type) |
||
| 56 | { |
||
| 57 | $account_options = array('account_type' => $type); |
||
| 58 | $accounts_type = Api\Accounts::link_query('',$account_options); |
||
| 59 | if($type == 'accounts') |
||
| 60 | { |
||
| 61 | $accounts_type = array_intersect_key($accounts_type, $GLOBALS['egw']->acl->get_grants('calendar')); |
||
| 62 | } |
||
| 63 | $accounts += $accounts_type; |
||
| 64 | } |
||
| 65 | $sel_options += array_map( |
||
| 66 | function($account_id, $account_name) { |
||
| 67 | return array( |
||
| 68 | 'value' => ''.$account_id, |
||
| 69 | 'label' => $account_name, |
||
| 70 | 'app' => lang('api-accounts') |
||
| 71 | ); |
||
| 72 | }, |
||
| 73 | array_keys($accounts), $accounts |
||
| 74 | ); |
||
| 75 | |||
| 76 | if(!is_array($value)) |
||
| 77 | { |
||
| 78 | // set value with an empty string only if sel options are not |
||
| 79 | // loaded, for example: setting calendar owner via URL when |
||
| 80 | // calendar app is not yet loaded. |
||
| 81 | $value = !empty($sel_options) ? array(): explode(',', $value); |
||
| 82 | } |
||
| 83 | |||
| 84 | // Add external owners that a select account widget will not find |
||
| 85 | foreach($value as &$owner) |
||
| 86 | { |
||
| 87 | $label = self::get_owner_label($owner); |
||
| 88 | $info = array(); |
||
| 89 | if(!is_numeric($owner)) |
||
| 90 | { |
||
| 91 | $resource = $bo->resources[substr($owner, 0,1)]; |
||
| 92 | if($resource['info'] && !($info = $bo->resource_info($owner))) |
||
| 93 | { |
||
| 94 | continue; // ignore that resource, we would get a PHP Fatal: Unsupported operand types |
||
| 95 | } |
||
| 96 | } |
||
| 97 | else if (!in_array($owner, array_keys($accounts))) |
||
| 98 | { |
||
| 99 | $resource = array('app'=> 'api-accounts'); |
||
| 100 | } |
||
| 101 | else |
||
| 102 | { |
||
| 103 | continue; |
||
| 104 | } |
||
| 105 | $sel_options[] = array('value' => $owner, 'label' => $label, 'app' => lang($resource['app'])) + $info; |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 278 |
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.