You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Read the base directory once where a method asks for it several times, and reuse the existing directory helpers where a path is built by hand. No behavior change.
Why
App::getBaseDir() is self::getContext()->getBaseDir(), so each call is cheap and this is about readability, not speed. It is called directly 17 times in 6 files in src/, and the base_dir() helper (src/App/Helpers/dir.php), which wraps the same call, is used 23 times in 20 files. The repetition has two forms:
the same call several times in one method: EnvCommand::exec() (4 times), Environment (3 times: load() and the env file path) and Config (2 times);
paths rebuilt by hand although a helper exists: LoadHelpersStage builds .../modules/*/helpers although modules_dir() exists, and ModuleLoader and Config both build .../shared/config, for which there is no shared_dir() helper.
Scope
In EnvCommand::exec(), Environment and Config, read the base directory into a local variable once.
Use modules_dir() in LoadHelpersStage where the modules path is rebuilt.
Decide whether a shared_dir() helper next to modules_dir() and logs_dir() is worth a new public helper; if not, leave the two shared/config paths as they are.
Acceptance Criteria
no method asks for the base directory more than once to build its paths
no behavior change: the existing tests pass, and a test covers a path that moves to a helper if none does
composer test, composer cs:check, composer phpstan and composer rector:check pass
Activity
[#633] Read the base directory once where it is asked several times