66
77use function Tempest \env ;
88
9+ /**
10+ * Represents the environment in which the application is running.
11+ */
912enum Environment: string
1013{
1114 case LOCAL = 'local ' ;
1215 case STAGING = 'staging ' ;
1316 case PRODUCTION = 'production ' ;
14- case CI = 'ci ' ;
17+ case CONTINUOUS_INTEGRATION = 'ci ' ;
1518 case TESTING = 'testing ' ;
16- case OTHER = 'other ' ;
1719
1820 public function isProduction (): bool
1921 {
@@ -30,24 +32,27 @@ public function isLocal(): bool
3032 return $ this === self ::LOCAL ;
3133 }
3234
33- public function isCI (): bool
35+ public function isContinuousIntegration (): bool
3436 {
35- return $ this === self ::CI ;
37+ return $ this === self ::CONTINUOUS_INTEGRATION ;
3638 }
3739
3840 public function isTesting (): bool
3941 {
4042 return $ this === self ::TESTING ;
4143 }
4244
43- public function isOther (): bool
45+ /**
46+ * Guesses the environment from the `ENVIRONMENT` environment variable.
47+ */
48+ public static function guessFromEnvironment (): self
4449 {
45- return $ this === self ::OTHER ;
46- }
50+ $ value = env ('ENVIRONMENT ' , default: 'local ' );
4751
48- public static function fromEnv (): self
49- {
50- $ value = env ('ENVIRONMENT ' , 'local ' );
52+ // Can be removed after https://github.com/tempestphp/tempest-framework/pull/1836
53+ if (is_null ($ value )) {
54+ $ value = 'local ' ;
55+ }
5156
5257 return self ::tryFrom ($ value ) ?? throw new EnvironmentValueWasInvalid ($ value );
5358 }
0 commit comments