Conditions | 12 |
Paths | 24 |
Total Lines | 85 |
Code Lines | 55 |
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 |
||
59 | static function settings($hook_data) |
||
60 | { |
||
61 | $settings = array(); |
||
62 | |||
63 | if ($hook_data['setup']) |
||
64 | { |
||
65 | $apps = array('addressbook','calendar','infolog'); |
||
66 | } |
||
67 | else |
||
68 | { |
||
69 | $apps = array_keys($GLOBALS['egw_info']['user']['apps']); |
||
70 | } |
||
71 | foreach($apps as $app) |
||
72 | { |
||
73 | $class_name = $app.'_groupdav'; |
||
74 | if (class_exists($class_name, true)) |
||
75 | { |
||
76 | $settings[] = array( |
||
77 | 'type' => 'section', |
||
78 | 'title' => $app, |
||
79 | ); |
||
80 | $settings += call_user_func(array($class_name,'get_settings'), $hook_data); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | $settings[] = array( |
||
85 | 'type' => 'section', |
||
86 | 'title' => 'Logging / debuging', |
||
87 | ); |
||
88 | $settings['debug_level'] = array( |
||
89 | 'type' => 'select', |
||
90 | 'label' => 'Enable logging', |
||
91 | 'name' => 'debug_level', |
||
92 | 'help' => 'Enables logging of CalDAV/CardDAV traffic to diagnose problems with devices.', |
||
93 | 'values' => array( |
||
94 | '0' => lang('Off'), |
||
95 | 'r' => lang('Requests and truncated responses to Apache error-log'), |
||
96 | 'f' => lang('Requests and full responses to files directory'), |
||
97 | ), |
||
98 | 'xmlrpc' => true, |
||
99 | 'admin' => false, |
||
100 | 'default' => '0', |
||
101 | ); |
||
102 | if ($GLOBALS['type'] === 'forced' || $GLOBALS['type'] === 'user' && |
||
103 | $GLOBALS['egw_info']['user']['preferences']['groupdav']['debug-log'] !== 'never') |
||
104 | { |
||
105 | if ($GLOBALS['type'] === 'user') |
||
106 | { |
||
107 | $logs = array(); |
||
108 | $relativ_log_dir .= 'groupdav/'.Api\CalDAV::sanitize_filename(Api\Accounts::id2name($hook_data['account_id'])); |
||
109 | $log_dir = $GLOBALS['egw_info']['server']['files_dir'].'/'.$relativ_log_dir; |
||
110 | if (file_exists($log_dir) && ($files = scandir($log_dir))) |
||
111 | { |
||
112 | foreach($files as $log) |
||
113 | { |
||
114 | if (substr($log, -4) == '.log') |
||
115 | { |
||
116 | $logs[$relativ_log_dir.'/'.$log] = Api\DateTime::to(filemtime($log_dir.'/'.$log)).': '. |
||
117 | str_replace('!', '/', $log); |
||
118 | } |
||
119 | } |
||
120 | } |
||
121 | $link = Api\Framework::link('/index.php',array( |
||
122 | 'menuaction' => 'api.'.__CLASS__.'.log', |
||
123 | 'filename' => '', |
||
124 | )); |
||
125 | $onchange = "egw_openWindowCentered('$link'+encodeURIComponent(this.value), '_blank', 1000, 500); this.value=''"; |
||
126 | } |
||
127 | else // allow to force users to NOT be able to delete their profiles |
||
128 | { |
||
129 | $logs = array('never' => lang('Never')); |
||
130 | } |
||
131 | $settings['show-log'] = array( |
||
132 | 'type' => 'select', |
||
133 | 'label' => 'Show log of following device', |
||
134 | 'name' => 'show-log', |
||
135 | 'help' => lang('You need to set enable logging to "%1" to create/update a log.', |
||
136 | lang('Requests and full responses to files directory')), |
||
137 | 'values' => $logs, |
||
138 | 'xmlrpc' => True, |
||
139 | 'admin' => False, |
||
140 | 'onchange' => $onchange, |
||
141 | ); |
||
142 | } |
||
143 | return $settings; |
||
144 | } |
||
169 | } |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.