Skip to content

Reduce the repeated base directory lookups #633

Closed

Description

@armanist

Summary

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

  1. added this to the 3.1.1 milestone on Oct 29, 2026
  2. added a commit that references this issue on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions