Conditions | 7 |
Paths | 48 |
Total Lines | 79 |
Code Lines | 35 |
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 |
||
128 | function start(array $forcedConfig=[]) |
||
129 | { |
||
130 | // Report all errors |
||
131 | ini_set('display_errors', 1); |
||
132 | error_reporting(E_ALL | E_STRICT); |
||
133 | |||
134 | // Set timezone to UTC so that times are consistent |
||
135 | date_default_timezone_set('UTC'); |
||
136 | |||
137 | // Get current microtime for performance measurement |
||
138 | $start = microtime(true); |
||
139 | |||
140 | // File extensions for autoloads |
||
141 | spl_autoload_extensions('.php'); |
||
142 | |||
143 | // Console, built-in-webserver and HHVM need some assistance |
||
144 | $sapi = strtolower(php_sapi_name()); |
||
145 | $need = ['cli', 'cli-server', 'srv']; |
||
146 | |||
147 | if (in_array($sapi, $need)) { |
||
148 | |||
149 | // Special case for commandline and builtin webserver |
||
150 | spl_autoload_register(__NAMESPACE__ . '\handlerAutoloads'); |
||
151 | |||
152 | } else { |
||
153 | |||
154 | spl_autoload_register(); |
||
155 | } |
||
156 | |||
157 | // Set error and exception handlers |
||
158 | spl_autoload_call('csphere\core\errors\Controller'); |
||
159 | set_error_handler(__NAMESPACE__ . '\handlerErrors'); |
||
160 | set_exception_handler(__NAMESPACE__ . '\handlerExceptions'); |
||
161 | register_shutdown_function(__NAMESPACE__ . '\handlerShutdown'); |
||
162 | |||
163 | // Read config file and check for errors |
||
164 | $conf = new \csphere\core\init\Config(); |
||
165 | $error = $conf->error(); |
||
166 | $config = $conf->get(); |
||
167 | |||
168 | //Overwrite default config values |
||
169 | foreach ($forcedConfig as $cat=>$values) { |
||
170 | foreach ($values as $key=>$value) { |
||
171 | $config[$cat][$key]=$value; |
||
172 | } |
||
173 | } |
||
174 | |||
175 | // Turn on display_errors if debug is activated |
||
176 | $debug = (empty($config['view']['debug'])) ? 0 : 1; |
||
177 | |||
178 | ini_set('display_errors', $debug); |
||
179 | |||
180 | // Check and set config flags |
||
181 | $config['view']['parsetime'] = $start; |
||
182 | |||
183 | if (empty($config['view']['driver'])) { |
||
184 | |||
185 | $config['view']['driver'] = 'html'; |
||
186 | $config['view']['theme'] = 'install'; |
||
187 | } |
||
188 | |||
189 | // Pass config to service loader |
||
190 | \csphere\core\service\Locator::start($config); |
||
191 | |||
192 | // Prepare input for later usage |
||
193 | \csphere\core\http\Input::prepare(); |
||
194 | |||
195 | // Execute request if no config error was found |
||
196 | if ($error == []) { |
||
197 | |||
198 | $router = new \csphere\core\router\Controller(true); |
||
199 | |||
200 | $router->execute(); |
||
201 | |||
202 | } else { |
||
203 | |||
204 | \csphere\core\errors\Startup::rescue($error); |
||
205 | } |
||
206 | } |
||
207 |