-
Notifications
You must be signed in to change notification settings - Fork 0
🧹 Refactor Init constructor for better readability #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,107 +22,132 @@ | |
|
|
||
| $this->actions = $actions; | ||
|
|
||
| $this->setup_environment(); | ||
|
|
||
| // Abort initialization here if fast init wanted (for tests/debug/do not use) | ||
| if ($this->actions->return_if_fast_init === true && defined('YOURLS_FAST_INIT') && YOURLS_FAST_INIT){ | ||
| return; | ||
| } | ||
|
|
||
| $this->setup_core(); | ||
| $this->setup_plugins(); | ||
| } | ||
|
|
||
| /** | ||
| * Set up the initial environment. | ||
| * | ||
| * @return void | ||
| */ | ||
| private function setup_environment() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The newly introduced helper method protected function setup_environment() { |
||
| // Include core files | ||
| if ($actions->include_core_funcs === true) { | ||
| if ($this->actions->include_core_funcs === true) { | ||
| $this->include_core_functions(); | ||
| } | ||
|
|
||
| // Enforce UTC timezone. Date/time can be adjusted with a plugin. | ||
| if ($actions->default_timezone === true) { | ||
| if ($this->actions->default_timezone === true) { | ||
| date_default_timezone_set( 'UTC' ); | ||
| } | ||
|
|
||
| // Check if we are in maintenance mode - if yes, it will die here. | ||
| if ($actions->check_maintenance_mode === true) { | ||
| if ($this->actions->check_maintenance_mode === true) { | ||
| yourls_check_maintenance_mode(); | ||
| } | ||
|
|
||
| // Compatibility: REQUEST_URI for IIS | ||
| if ($actions->fix_request_uri === true) { | ||
| if ($this->actions->fix_request_uri === true) { | ||
| yourls_fix_request_uri(); | ||
| } | ||
|
|
||
| // If request for an admin page is http:// and SSL is required, redirect | ||
| if ($actions->redirect_ssl === true) { | ||
| if ($this->actions->redirect_ssl === true) { | ||
| $this->redirect_ssl_if_needed(); | ||
| } | ||
|
|
||
| // Create the YOURLS object $ydb that will contain everything we globally need | ||
| if ($actions->include_db === true) { | ||
| if ($this->actions->include_db === true) { | ||
| $this->include_db_files(); | ||
| } | ||
|
|
||
| // Allow early and unconditional inclusion of custom code | ||
| if ($actions->include_cache === true) { | ||
| if ($this->actions->include_cache === true) { | ||
| $this->include_cache_files(); | ||
| } | ||
| } | ||
|
|
||
| // Abort initialization here if fast init wanted (for tests/debug/do not use) | ||
| if ($actions->return_if_fast_init === true && defined('YOURLS_FAST_INIT') && YOURLS_FAST_INIT){ | ||
| return; | ||
| } | ||
|
|
||
| /** | ||
| * Load core options and check for install/upgrade. | ||
| * | ||
| * @return void | ||
| */ | ||
| private function setup_core() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // Read options right from start | ||
| if ($actions->get_all_options === true) { | ||
| if ($this->actions->get_all_options === true) { | ||
| yourls_get_all_options(); | ||
| } | ||
|
|
||
| // Register shutdown function | ||
| if ($actions->register_shutdown === true) { | ||
| if ($this->actions->register_shutdown === true) { | ||
| register_shutdown_function( 'yourls_shutdown' ); | ||
| } | ||
|
|
||
| // Core now loaded | ||
| if ($actions->core_loaded === true) { | ||
| if ($this->actions->core_loaded === true) { | ||
| yourls_do_action( 'init' ); // plugins can't see this, not loaded yet | ||
| } | ||
|
|
||
| // Check if need to redirect to install procedure | ||
| if ($actions->redirect_to_install === true) { | ||
| if ($this->actions->redirect_to_install === true) { | ||
| if (!yourls_is_installed() && !yourls_is_installing()) { | ||
| yourls_no_cache_headers(); | ||
| yourls_redirect( yourls_admin_url('install.php'), 307 ); | ||
| exit(); | ||
| } | ||
| } | ||
|
|
||
| // Check if upgrade is needed (bypassed if upgrading or installing) | ||
| if ($actions->check_if_upgrade_needed === true) { | ||
| if ($this->actions->check_if_upgrade_needed === true) { | ||
| if (!yourls_is_upgrading() && !yourls_is_installing() && yourls_upgrade_is_needed()) { | ||
| yourls_no_cache_headers(); | ||
| yourls_redirect( yourls_admin_url('upgrade.php'), 307 ); | ||
| exit(); | ||
| } | ||
| } | ||
| } | ||
Check warningCode scanning / PHPMD Code Size Rules: CyclomaticComplexity Warning
The method setup_core() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
|
||
|
Comment on lines
83
to
116
|
||
|
|
||
| /** | ||
| * Load plugins, locales, and admin updates. | ||
| * | ||
| * @return void | ||
| */ | ||
| private function setup_plugins() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // Load all plugins | ||
| if ($actions->load_plugins === true) { | ||
| if ($this->actions->load_plugins === true) { | ||
| yourls_load_plugins(); | ||
| } | ||
|
|
||
| // Trigger plugin loaded action | ||
| if ($actions->plugins_loaded_action === true) { | ||
| if ($this->actions->plugins_loaded_action === true) { | ||
| yourls_do_action( 'plugins_loaded' ); | ||
| } | ||
|
|
||
| // Load locale | ||
| if ($actions->load_default_textdomain === true) { | ||
| if ($this->actions->load_default_textdomain === true) { | ||
| yourls_load_default_textdomain(); | ||
| } | ||
|
|
||
| // Is there a new version of YOURLS ? | ||
| if ($actions->check_new_version === true) { | ||
| if ($this->actions->check_new_version === true) { | ||
| if (yourls_is_installed() && !yourls_is_upgrading()) { | ||
| yourls_tell_if_new_version(); | ||
| } | ||
| } | ||
|
|
||
| if ($actions->init_admin === true) { | ||
| if ($this->actions->init_admin === true) { | ||
| if (yourls_is_admin()) { | ||
| yourls_do_action( 'admin_init' ); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a missing space between the closing parenthesis and the opening brace
){which is inconsistent with the rest of the file's formatting and standard PSR-12 style guidelines. Adding a space improves readability.