From ce1e7db789fb30d3d3f63d61f66cc112188e0fc7 Mon Sep 17 00:00:00 2001 From: Hector Mendoza Jacobo Date: Mon, 9 Sep 2024 21:40:16 +0000 Subject: [PATCH] Change logic for getDefaultLogger --- src/ApplicationDefaultCredentials.php | 22 +++++++++++++++----- tests/HttpHandler/Guzzle7HttpHandlerTest.php | 1 - 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/ApplicationDefaultCredentials.php b/src/ApplicationDefaultCredentials.php index 6632fed9f..19a7b1ff6 100644 --- a/src/ApplicationDefaultCredentials.php +++ b/src/ApplicationDefaultCredentials.php @@ -332,18 +332,30 @@ public static function getIdTokenCredentials( public static function getDefaultLogger(): null|LoggerInterface { $loggingFlag = getenv(self::SDK_DEBUG_FLAG); - if ($loggingFlag instanceof string) { - $loggingFlag = strtolower($loggingFlag); + + // Env var is not set + if (!is_string($loggingFlag)) { + if (is_array($loggingFlag)) { + trigger_error('The ' . self::SDK_DEBUG_FLAG . ' is set, but it is set to another value than false, true, 0 or 1. Logging is disabled'); + return null; + } + + return null; } - if ($loggingFlag === false || $loggingFlag !== 'true' && $loggingFlag !== '1') { - if (strtolower($loggingFlag) !== 'false' && strtolower($loggingFlag) !== '0') { - trigger_error('The ' . self::SDK_DEBUG_FLAG . ' is set, but it is set to another value than false, true or 0. Logging is disabled'); + $loggingFlag = strtolower($loggingFlag); + + // Env Var is not true + if ($loggingFlag !== 'true' && $loggingFlag !== '1') { + // Env var is set to a non valid value + if ($loggingFlag !== 'false' && $loggingFlag !== '0') { + trigger_error('The ' . self::SDK_DEBUG_FLAG . ' is set, but it is set to another value than false, true, 0 or 1. Logging is disabled'); } return null; } + return new StdOutLogger(); } diff --git a/tests/HttpHandler/Guzzle7HttpHandlerTest.php b/tests/HttpHandler/Guzzle7HttpHandlerTest.php index 3d1204929..221b4d39e 100644 --- a/tests/HttpHandler/Guzzle7HttpHandlerTest.php +++ b/tests/HttpHandler/Guzzle7HttpHandlerTest.php @@ -24,7 +24,6 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use Prophecy\Argument; -use Prophecy\Promise\ReturnPromise; use Psr\Log\LoggerInterface; /**