Skip to content

Improve autoloader flexibility by removing hardcoded directory mappings.#1199

Merged
mauteri merged 1 commit intodevelopfrom
autoloader-improvement
Oct 5, 2025
Merged

Improve autoloader flexibility by removing hardcoded directory mappings.#1199
mauteri merged 1 commit intodevelopfrom
autoloader-improvement

Conversation

@mauteri
Copy link
Copy Markdown
Contributor

@mauteri mauteri commented Oct 5, 2025

Description of the Change

Replace hardcoded switch statement with automatic directory detection, allowing new class types to be added without modifying the autoloader code.

How to test the Change

All classes still load via autoloader without fatal error.

Changelog Entry

Changed - Existing functionality

Credits

Props @mauteri

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@what-the-diff
Copy link
Copy Markdown

what-the-diff bot commented Oct 5, 2025

PR Summary

  • Enhanced directory check for class types
    Instead of using a "switch" statement, which is a control flow statement, to handle the different types of classes we have, we improved it by creating a specialized directory for each class type. We use a function 'is_dir()' to verify if a specified directory for a class type exists.

  • Logic addition to ascertain existence of specialized directory
    We added a decision-making process to verify if a specialized directory is already available for the class type at hand. This is done to manage folders in an organized way. Our code now adjusts the $structure array based on whether or not the directory exists.

  • Simplified class type handling by removing the default case
    The default action in the "switch" statement, which assumed responsibility when none of the specified cases matched, has been removed. This is an intentional decision to make the management of class types more straightforward. We're streamlining the process, avoiding unnecessary pathways in the code.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 5, 2025

Preview changes with Playground

You can preview the recent changes for PR#1199 with the following PHP versions:

PHP Version 8.3

PHP Version 7.4

Download .zip with build changes

Made with 💙 from GatherPress & a little bit of WordPress Playground. Changes will not persist between sessions.

@mauteri mauteri requested a review from jmarx October 5, 2025 20:46
Copy link
Copy Markdown
Collaborator

@jmarx jmarx left a comment

Choose a reason for hiding this comment

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

LGTM

@mauteri mauteri merged commit 77caccd into develop Oct 5, 2025
16 checks passed
@mauteri mauteri deleted the autoloader-improvement branch October 5, 2025 22:24
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