Make the plugin file the composition root#46
Merged
Conversation
ARCHITECTURE.md is explicit that no Plugin class is needed: the main file defines one constant, loads the autoloader and wires features through a bootstrapper. The former Plugin was only ever the settings page, so it becomes a SettingsPage feature the Bootstrapper registers, and PLUGIN_SLUG_FILE returns as the single source every path derives from.
PHPStan does not evaluate the runtime define() in the plugin file, so a bootstrap file tells it about PLUGIN_SLUG_FILE. The classes can then use the constant directly while analysis stays at max.
Splits the former Plugin tests to match the new classes and adds the bootstrapper's wiring, holding mutation coverage at 100%.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
Pluginclass had become a single-responsibility class wearing the wrong name: everything it did was the settings page. ARCHITECTURE.md is unambiguous that a plugin does not need aPluginclass at all — the main file defines one constant, loads the autoloader, and wires its features through a bootstrapper. My earlier brightnucleus change kept aPluginclass and injected__FILE__into it, which quietly diverged from that. This realigns it.plugin-slug.phpis now the composition root: it definesPLUGIN_SLUG_FILE— the single constant every path derives from at runtime — and onplugins_loadedhands off to aBootstrapper. The bootstrapper is the one place features are registered; today it registers aSettingsPage, which holds whatPluginused to, and new features slot in beside it. NoPluginclass, no globals.The one wrinkle is that referencing
PLUGIN_SLUG_FILEinside a class is what previously blocked PHPStan's top level, since PHPStan does not evaluate the runtimedefine(). Rather than route around it by injecting the path, a small bootstrap file declares the constant for analysis, so the classes use it directly — as the standard writes it — and analysis stays atmax.The boilerplate stays flat and container-less; the DI container and layered namespaces ARCHITECTURE.md shows are the scale-up path, not something to impose on a single settings page. The tests split to match the new classes, the bootstrapper's wiring is covered with a
@usesannotation for the feature it registers, and mutation coverage holds at 100%.