Skip to content

🧹 Refactor Init constructor for better readability#230

Merged
projectedanx merged 1 commit into
masterfrom
jules-14191460669248153549-d37f55f7
Jun 6, 2026
Merged

🧹 Refactor Init constructor for better readability#230
projectedanx merged 1 commit into
masterfrom
jules-14191460669248153549-d37f55f7

Conversation

@projectedanx

Copy link
Copy Markdown
Owner

🎯 What: The __construct method in includes/Config/Init.php was 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 Init class constructor is now much cleaner and easier to read. The initialization logic is preserved exactly as before but modularized into setup_environment(), setup_core(), and setup_plugins() while maintaining the precise placement of the fast-init early return check.


PR created automatically by Jules for task 14191460669248153549 started by @projectedanx

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread includes/Config/Init.php
*
* @return void
*/
private function setup_environment() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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() {

Comment thread includes/Config/Init.php
*
* @return void
*/
private function setup_core() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The newly introduced helper method setup_core is declared as private. For consistency and to allow subclasses to override or hook into specific initialization phases, it is recommended to change its visibility to protected.

    protected function setup_core() {

Comment thread includes/Config/Init.php
*
* @return void
*/
private function setup_plugins() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The newly introduced helper method setup_plugins is declared as private. For consistency and to allow subclasses to override or hook into specific initialization phases, it is recommended to change its visibility to protected.

    protected function setup_plugins() {

Comment thread includes/Config/Init.php
$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){

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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) {

Comment thread includes/Config/Init.php
Comment on lines 83 to 116
@@ -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();
}
}
}

@projectedanx projectedanx merged commit 6cf2b34 into master Jun 6, 2026
15 of 16 checks passed
@projectedanx projectedanx deleted the jules-14191460669248153549-d37f55f7 branch June 6, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants