🧹 Refactor Init constructor for better readability#230
Conversation
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Code Review
This pull request refactors the Init class constructor by extracting its initialization logic into three new helper methods: setup_environment(), setup_core(), and setup_plugins(). The review feedback recommends changing the visibility of these new helper methods from private to protected to support extensibility and maintain consistency with other helper methods in the class. Additionally, a minor formatting correction is suggested to add a missing space before an opening brace in a conditional statement.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| * | ||
| * @return void | ||
| */ | ||
| private function setup_environment() { |
There was a problem hiding this comment.
The newly introduced helper method setup_environment is declared as private. Since the Init class is not marked as final and can be extended, and all other helper methods in this class (such as redirect_ssl_if_needed, include_db_files, etc.) are public, using private restricts extensibility and is inconsistent with the rest of the class design. Changing this method to protected allows subclasses to override or hook into specific initialization phases if needed (e.g., during testing or custom bootstrapping).
protected function setup_environment() {| * | ||
| * @return void | ||
| */ | ||
| private function setup_core() { |
| * | ||
| * @return void | ||
| */ | ||
| private function setup_plugins() { |
There was a problem hiding this comment.
| $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){ |
There was a problem hiding this comment.
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.
if ($this->actions->return_if_fast_init === true && defined('YOURLS_FAST_INIT') && YOURLS_FAST_INIT) {| @@ -87,42 +106,48 @@ public function __construct(InitDefaults $actions) { | |||
| } | |||
|
|
|||
| // 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(); | |||
| } | |||
| } | |||
| } | |||
|
|
|||
🎯 What: The
__constructmethod inincludes/Config/Init.phpwas overly complex, handling several stages of application initialization in a single procedural block. It has been refactored by extracting logically grouped operations into smaller, private helper methods.💡 Why: Constructors should ideally be lightweight. Extracting initialization steps into private methods improves code readability and maintainability by organizing related setup tasks (environment, core features, plugins) into dedicated methods, adhering to single-responsibility principles.
✅ Verification: A PHP syntax check was run to ensure basic correctness. The local test suite was successfully executed with MariaDB set up to verify that existing functionality works as intended. Code reviews confirmed no logical side effects.
✨ Result: The
Initclass constructor is now much cleaner and easier to read. The initialization logic is preserved exactly as before but modularized intosetup_environment(),setup_core(), andsetup_plugins()while maintaining the precise placement of the fast-init early return check.PR created automatically by Jules for task 14191460669248153549 started by @projectedanx