66
77use Laminas \AutomaticReleases \Gpg \ImportGpgKeyFromString ;
88use Laminas \AutomaticReleases \Gpg \SecretKeyId ;
9- use Psl ;
10- use Psl \Env ;
11- use Psl \Iter ;
12- use Psl \Str ;
9+
10+ use function Psl \Env \get_var ;
11+ use function Psl \invariant ;
12+ use function Psl \Iter \contains ;
13+ use function Psl \Str \format ;
1314
1415/** @psalm-immutable */
1516class EnvironmentVariables implements Variables
@@ -51,8 +52,8 @@ private function __construct(
5152 private readonly string $ logLevel ,
5253 ) {
5354 /** @psalm-suppress ImpureFunctionCall the {@see \Psl\Iter\contains()} API is conditionally pure */
54- Psl \ invariant (
55- Iter \ contains (self ::LOG_LEVELS , $ logLevel ),
55+ invariant (
56+ contains (self ::LOG_LEVELS , $ logLevel ),
5657 'LOG_LEVEL env MUST be a valid monolog/monolog log level constant name or value; '
5758 . ' see https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#log-levels ' ,
5859 );
@@ -62,25 +63,33 @@ public static function fromEnvironment(ImportGpgKeyFromString $importKey): self
6263 {
6364 return new self (
6465 self ::getenv ('GITHUB_TOKEN ' ),
65- $ importKey-> __invoke (self ::getenv ('SIGNING_SECRET_KEY ' )),
66+ ( $ importKey) (self ::getenv ('SIGNING_SECRET_KEY ' )),
6667 self ::getenv ('GIT_AUTHOR_NAME ' ),
6768 self ::getenv ('GIT_AUTHOR_EMAIL ' ),
6869 self ::getenv ('GITHUB_EVENT_PATH ' ),
6970 self ::getenv ('GITHUB_WORKSPACE ' ),
70- self ::getenvWithFallback ('LOG_LEVEL ' , 'INFO ' ),
71+ self ::getenvWithFallback (
72+ 'LOG_LEVEL ' ,
73+ self ::isDebugMode () ? 'DEBUG ' : 'INFO ' ,
74+ ),
7175 );
7276 }
7377
78+ private static function isDebugMode (): bool
79+ {
80+ return get_var ('ACTIONS_RUNNER_DEBUG ' ) !== null ;
81+ }
82+
7483 /**
7584 * @psalm-param non-empty-string $key
7685 *
7786 * @psalm-return non-empty-string
7887 */
7988 private static function getenv (string $ key ): string
8089 {
81- $ value = Env \ get_var ($ key );
90+ $ value = get_var ($ key );
8291
83- Psl \ invariant ($ value !== null && $ value !== '' , Str \ format ('Could not find a value for environment variable "%s" ' , $ key ));
92+ invariant ($ value !== null && $ value !== '' , format ('Could not find a value for environment variable "%s" ' , $ key ));
8493
8594 return $ value ;
8695 }
@@ -93,7 +102,7 @@ private static function getenv(string $key): string
93102 */
94103 private static function getenvWithFallback (string $ key , string $ default ): string
95104 {
96- $ value = Env \ get_var ($ key );
105+ $ value = get_var ($ key );
97106
98107 return $ value === null || $ value === '' ? $ default : $ value ;
99108 }
@@ -120,7 +129,6 @@ public function gitAuthorEmail(): string
120129
121130 public function githubEventPath (): string
122131 {
123- // @TODO test me
124132 return $ this ->githubEventPath ;
125133 }
126134
0 commit comments