Skip to content

Split the Environment class into a contract and traits #614

Open

Description

@armanist

Summary

Split the Environment class into a contract and traits, as other packages do, with no behavior change. The typed readers that go into the new contract are tracked separately in #615.

Why

Quantum\Environment\Environment is one 213-line class with five jobs: state and loading, the app environment name, reading values, writing .env, and locating and parsing the files. It has no interface, unlike Config and Mailer, and the readers planned in #615 need a contract to be defined in.

Proposed change

src/Environment/
├── Contracts/EnvironmentInterface.php
├── Environment.php                 state and load(), using the traits
├── Traits/
│   ├── AppEnvTrait.php             getAppEnv(), isProduction(), isStaging(), isDevelopment(), isTesting(), isLocal()
│   ├── ValueTrait.php              getValue(), hasKey(), getRow()
│   └── EnvFileTrait.php            file lookup, parsing and updateRow()
├── Enums/, Exceptions/, Helpers/, Server.php
  • EnvironmentInterface declares every public method of the class. setMutable() returns EnvironmentInterface in the contract, and Environment keeps : Environment, which narrows it.
  • Environment keeps all its public methods, so environment(), env(), AppContext and the other users do not change.

Out of scope

Breaking changes

  • None.

Acceptance criteria

  • EnvironmentInterface exists and Environment implements it
  • the traits hold the code listed above, and Environment keeps only state and load()
  • the existing environment tests pass without edits
  • composer test, composer cs:check, composer phpstan and composer rector:check pass on every PHP version in the CI matrix
  • the changelog lists the change

Activity

  1. added this to the 3.1.2 milestone on Oct 26, 2026
  2. changed the title [-]Split the Environment class into a contract and traits, and add typed readers[/-] [+]Split the Environment class into a contract and traits[/+] on Oct 26, 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

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions