| Total Complexity | 83 |
| Total Lines | 453 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Bootstrap often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Bootstrap, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 37 | class Bootstrap |
||
| 38 | { |
||
| 39 | /** @var array What is returned by the function getrusage. */ |
||
| 40 | protected $rusage_start = []; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Bootstrap constructor. |
||
| 44 | * |
||
| 45 | * @param bool $standalone |
||
| 46 | * - True to boot outside elkarte |
||
| 47 | * - False to bootstrap the main elkarte site. |
||
| 48 | */ |
||
| 49 | public function __construct($standalone = true) |
||
| 50 | { |
||
| 51 | // Bootstrap only once. |
||
| 52 | if (!defined('ELKBOOT')) |
||
| 53 | { |
||
| 54 | // We're going to set a few globals |
||
| 55 | global $time_start, $ssi_error_reporting, $db_show_debug; |
||
| 56 | |||
| 57 | // Your on the clock |
||
| 58 | $time_start = microtime(true); |
||
| 59 | |||
| 60 | // Unless settings.php tells us otherwise |
||
| 61 | $db_show_debug = false; |
||
| 62 | |||
| 63 | // Report errors but not depreciated ones |
||
| 64 | $ssi_error_reporting = error_reporting(E_ALL & ~E_DEPRECATED); |
||
| 65 | |||
| 66 | // Get the things needed for ALL modes |
||
| 67 | $this->bringUpBasics(); |
||
| 68 | |||
| 69 | // Going to run from the side entrance and not directly from inside elkarte |
||
| 70 | if ($standalone) |
||
| 71 | { |
||
| 72 | $this->ssi_main(); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Calls various initialization functions in the necessary order |
||
| 79 | */ |
||
| 80 | public function bringUpBasics() |
||
| 81 | { |
||
| 82 | $this->setConstants(); |
||
| 83 | $this->setRusage(); |
||
| 84 | $this->clearGlobals(); |
||
| 85 | $this->loadSettingsFile(); |
||
| 86 | $this->validatePaths(); |
||
| 87 | $this->loadDependants(); |
||
| 88 | $this->loadAutoloader(); |
||
| 89 | $this->checkMaintance(); |
||
| 90 | $this->setDebug(); |
||
| 91 | $this->bringUp(); |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Set the core constants, you know the ones we often forget to |
||
| 96 | * update on new releases. |
||
| 97 | */ |
||
| 98 | private function setConstants() |
||
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Get initial resource usage |
||
| 117 | */ |
||
| 118 | private function setRusage() |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * If they glo, they need to be cleaned. |
||
| 125 | */ |
||
| 126 | private function clearGlobals() |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Loads the Settings.php values into the global space |
||
| 140 | */ |
||
| 141 | private function loadSettingsFile() |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Validate the paths set in Settings.php, correct as needed and move them to constants. |
||
| 189 | */ |
||
| 190 | private function validatePaths() |
||
| 191 | { |
||
| 192 | global $boarddir, $sourcedir, $cachedir, $extdir, $languagedir; |
||
| 193 | |||
| 194 | // Make sure the paths are correct... at least try to fix them. |
||
| 195 | if (!file_exists($boarddir) && file_exists(__DIR__ . '/bootstrap.php')) |
||
| 196 | { |
||
| 197 | $boarddir = __DIR__; |
||
| 198 | } |
||
| 199 | |||
| 200 | if (!file_exists($sourcedir . '/SiteDispatcher.class.php') && file_exists($boarddir . '/sources')) |
||
| 201 | { |
||
| 202 | $sourcedir = $boarddir . '/sources'; |
||
| 203 | } |
||
| 204 | |||
| 205 | // Check that directories which didn't exist in past releases are initialized. |
||
| 206 | if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
||
| 207 | { |
||
| 208 | $cachedir = $boarddir . '/cache'; |
||
| 209 | } |
||
| 210 | |||
| 211 | if ((empty($extdir) || !file_exists($extdir)) && file_exists($sourcedir . '/ext')) |
||
| 212 | { |
||
| 213 | $extdir = $sourcedir . '/ext'; |
||
| 214 | } |
||
| 215 | |||
| 216 | if ((empty($languagedir) || !file_exists($languagedir)) && file_exists($sourcedir . '/Languages/Index')) |
||
| 217 | { |
||
| 218 | $languagedir = $sourcedir . '/ElkArte/Languages'; |
||
| 219 | } |
||
| 220 | |||
| 221 | // Time to forget about variables and go with constants! |
||
| 222 | define('BOARDDIR', $boarddir); |
||
| 223 | define('CACHEDIR', $cachedir); |
||
| 224 | define('EXTDIR', $extdir); |
||
| 225 | define('LANGUAGEDIR', $languagedir); |
||
| 226 | define('SOURCEDIR', $sourcedir); |
||
| 227 | define('ADMINDIR', $sourcedir . '/ElkArte/AdminController'); |
||
| 228 | define('CONTROLLERDIR', $sourcedir . '/ElkArte/Controller'); |
||
| 229 | define('SUBSDIR', $sourcedir . '/subs'); |
||
| 230 | define('ADDONSDIR', $boarddir . '/Addons'); |
||
| 231 | define('ELKARTEDIR', $sourcedir . '/ElkArte'); |
||
| 232 | unset($boarddir, $cachedir, $sourcedir, $languagedir, $extdir); |
||
| 233 | } |
||
| 234 | |||
| 235 | /** |
||
| 236 | * We require access to several important files, so load them upfront |
||
| 237 | */ |
||
| 238 | private function loadDependants() |
||
| 239 | { |
||
| 240 | // Files we cannot live without. |
||
| 241 | require_once(SOURCEDIR . '/QueryString.php'); |
||
| 242 | require_once(SOURCEDIR . '/Session.php'); |
||
| 243 | require_once(SOURCEDIR . '/Subs.php'); |
||
| 244 | require_once(SOURCEDIR . '/Logging.php'); |
||
| 245 | require_once(SOURCEDIR . '/Load.php'); |
||
| 246 | require_once(SOURCEDIR . '/Security.php'); |
||
| 247 | require_once(SUBSDIR . '/Cache.subs.php'); |
||
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * The autoloader will take care of most requests for files |
||
| 252 | */ |
||
| 253 | private function loadAutoloader() |
||
| 254 | { |
||
| 255 | require_once(EXTDIR . '/ClassLoader.php'); |
||
| 256 | |||
| 257 | $loader = new ClassLoader(); |
||
| 258 | $loader->setPsr4('ElkArte\\', SOURCEDIR . '/ElkArte'); |
||
| 259 | $loader->setPsr4('BBC\\', SOURCEDIR . '/ElkArte/BBC'); |
||
| 260 | $loader->setPsr4('Addons\\', BOARDDIR . '/Addons'); |
||
| 261 | $loader->register(); |
||
| 262 | } |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Check if we are in maintenance mode, if so end here. |
||
| 266 | */ |
||
| 267 | private function checkMaintance() |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | * If you like lots of debug information in error messages and below the footer |
||
| 292 | * then set $db_show_debug to true in settings. Don't do this on a production site. |
||
| 293 | */ |
||
| 294 | private function setDebug() |
||
| 303 | } |
||
| 304 | } |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Time to see what has been requested, by whom and dispatch it to the proper handler |
||
| 308 | */ |
||
| 309 | private function bringUp() |
||
| 332 | } |
||
| 333 | } |
||
| 334 | |||
| 335 | /** |
||
| 336 | * If you are running SSI standalone, you need to call this function after bootstrap is |
||
| 337 | * initialized. |
||
| 338 | */ |
||
| 339 | public function ssi_main() |
||
| 472 | } |
||
| 473 | |||
| 474 | /** |
||
| 475 | * Used to ensure SSI requests are valid and not a probing attempt |
||
| 476 | */ |
||
| 477 | private function _validRequestCheck() |
||
| 490 | } |
||
| 491 | } |
||
| 493 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths