| Conditions | 12 |
| Paths | 20 |
| Total Lines | 73 |
| Code Lines | 40 |
| 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 |
||
| 119 | public static function load_egw($user,$passwd,$domain='default',$info=array()) |
||
| 120 | { |
||
| 121 | $_REQUEST['domain'] = $domain; |
||
| 122 | $GLOBALS['egw_login_data'] = array( |
||
| 123 | 'login' => $user, |
||
| 124 | 'passwd' => $passwd, |
||
| 125 | 'passwd_type' => 'text', |
||
| 126 | ); |
||
| 127 | |||
| 128 | if (ini_get('session.save_handler') == 'files' && !is_writable(ini_get('session.save_path')) && is_dir('/tmp') && is_writable('/tmp')) |
||
| 129 | { |
||
| 130 | ini_set('session.save_path','/tmp'); // regular users may have no rights to apache's session dir |
||
| 131 | } |
||
| 132 | |||
| 133 | if(!$info) |
||
| 134 | { |
||
| 135 | $info = array( |
||
| 136 | 'flags' => array( |
||
| 137 | 'currentapp' => 'api', |
||
| 138 | 'noheader' => true, |
||
| 139 | 'autocreate_session_callback' => __CLASS__ .'::create_session', |
||
| 140 | 'no_exception_handler' => 'cli', |
||
| 141 | 'noapi' => false, |
||
| 142 | ) |
||
| 143 | ); |
||
| 144 | } |
||
| 145 | $GLOBALS['egw_info'] = $info; |
||
| 146 | |||
| 147 | $ob_level = ob_get_level(); |
||
| 148 | try |
||
| 149 | { |
||
| 150 | include(realpath(__DIR__ . '/../../header.inc.php')); |
||
| 151 | } |
||
| 152 | catch (Exception $e) |
||
| 153 | { |
||
| 154 | // Something went wrong setting up egw environment - don't try |
||
| 155 | // to do the test |
||
| 156 | static::markTestSkipped($e->getMessage()); |
||
| 157 | return; |
||
| 158 | } |
||
| 159 | |||
| 160 | require_once realpath(__DIR__.'/../src/loader/common.php'); // autoloader & check_load_extension |
||
| 161 | |||
| 162 | // egw is normally created when a file is loaded using require_once |
||
| 163 | if(empty($GLOBALS['egw']) || !is_a($GLOBALS['egw'], 'EGroupware\Api\Egw\Base')) |
||
| 164 | { |
||
| 165 | // From Api/src/loader.php |
||
| 166 | $GLOBALS['egw_info']['user']['domain'] = Api\Session::search_instance( |
||
| 167 | isset($_POST['login']) ? $_POST['login'] : (isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : $_SERVER['REMOTE_USER']), |
||
| 168 | Api\Session::get_request('domain'),$GLOBALS['egw_info']['server']['default_domain'], |
||
| 169 | array($_SERVER['HTTP_HOST'], $_SERVER['SERVER_NAME']),$GLOBALS['egw_domain']); |
||
| 170 | |||
| 171 | $GLOBALS['egw_info']['server']['db_host'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['db_host']; |
||
| 172 | $GLOBALS['egw_info']['server']['db_port'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['db_port']; |
||
| 173 | $GLOBALS['egw_info']['server']['db_name'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['db_name']; |
||
| 174 | $GLOBALS['egw_info']['server']['db_user'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['db_user']; |
||
| 175 | $GLOBALS['egw_info']['server']['db_pass'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['db_pass']; |
||
| 176 | $GLOBALS['egw_info']['server']['db_type'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['db_type']; |
||
| 177 | |||
| 178 | $GLOBALS['egw'] = new Api\Egw(array_keys($GLOBALS['egw_domain'])); |
||
| 179 | } |
||
| 180 | |||
| 181 | // load up the $GLOBALS['egw_info']['server'] array |
||
| 182 | $GLOBALS['egw_info']['server'] += Config::read('phpgwapi'); |
||
| 183 | // Make sure user is properly set |
||
| 184 | $GLOBALS['egw_info']['user'] = $GLOBALS['egw']->session->read_repositories(); |
||
| 185 | |||
| 186 | // Disable asyc while we test |
||
| 187 | $GLOBALS['egw_info']['server']['asyncservice'] = 'off'; |
||
| 188 | |||
| 189 | while(ob_get_level() > $ob_level) |
||
| 190 | { |
||
| 191 | ob_end_flush(); |
||
| 192 | } |
||
| 236 | } |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.