1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-30 09:50:26 +02:00

Updating while loops to have boolean conditions. (#1956)

* Updating while loops to have boolean conditions.

* Refactor exception normalization logic in LineFormatter for improved readability and efficiency

* Update retry logic in Curl Util to use retry count .

* Skip the if now that we check before starting the loop

---------

Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>
This commit is contained in:
Rajmund
2025-03-20 09:59:33 +01:00
committed by GitHub
parent 62946513d4
commit 5d0da0a798
2 changed files with 12 additions and 14 deletions

View File

@@ -204,16 +204,15 @@ class LineFormatter extends NormalizerFormatter
{
$str = $this->formatException($e);
if (($previous = $e->getPrevious()) instanceof \Throwable) {
do {
$depth++;
if ($depth > $this->maxNormalizeDepth) {
$str .= "\n[previous exception] Over " . $this->maxNormalizeDepth . ' levels deep, aborting normalization';
break;
}
$str .= "\n[previous exception] " . $this->formatException($previous);
} while ($previous = $previous->getPrevious());
$previous = $e->getPrevious();
while ($previous instanceof \Throwable) {
$depth++;
if ($depth > $this->maxNormalizeDepth) {
$str .= "\n[previous exception] Over " . $this->maxNormalizeDepth . ' levels deep, aborting normalization';
break;
}
$str .= "\n[previous exception] " . $this->formatException($previous);
$previous = $previous->getPrevious();
}
return $str;

View File

@@ -37,9 +37,10 @@ final class Util
* @param CurlHandle $ch curl handler
* @return bool|string @see curl_exec
*/
public static function execute(CurlHandle $ch, int $retries = 5, bool $closeAfterDone = true)
public static function execute(CurlHandle $ch, int $retries = 5, bool $closeAfterDone = true): bool|string
{
while ($retries--) {
while ($retries > 0) {
$retries--;
$curlResponse = curl_exec($ch);
if ($curlResponse === false) {
$curlErrno = curl_errno($ch);
@@ -53,7 +54,6 @@ final class Util
throw new \RuntimeException(sprintf('Curl error (code %d): %s', $curlErrno, $curlError));
}
continue;
}
@@ -63,7 +63,6 @@ final class Util
return $curlResponse;
}
return false;
}
}