1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-04 20:27:31 +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); $str = $this->formatException($e);
if (($previous = $e->getPrevious()) instanceof \Throwable) { $previous = $e->getPrevious();
do { while ($previous instanceof \Throwable) {
$depth++; $depth++;
if ($depth > $this->maxNormalizeDepth) { if ($depth > $this->maxNormalizeDepth) {
$str .= "\n[previous exception] Over " . $this->maxNormalizeDepth . ' levels deep, aborting normalization'; $str .= "\n[previous exception] Over " . $this->maxNormalizeDepth . ' levels deep, aborting normalization';
break; break;
} }
$str .= "\n[previous exception] " . $this->formatException($previous); $str .= "\n[previous exception] " . $this->formatException($previous);
} while ($previous = $previous->getPrevious()); $previous = $previous->getPrevious();
} }
return $str; return $str;

View File

@@ -37,9 +37,10 @@ final class Util
* @param CurlHandle $ch curl handler * @param CurlHandle $ch curl handler
* @return bool|string @see curl_exec * @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); $curlResponse = curl_exec($ch);
if ($curlResponse === false) { if ($curlResponse === false) {
$curlErrno = curl_errno($ch); $curlErrno = curl_errno($ch);
@@ -53,7 +54,6 @@ final class Util
throw new \RuntimeException(sprintf('Curl error (code %d): %s', $curlErrno, $curlError)); throw new \RuntimeException(sprintf('Curl error (code %d): %s', $curlErrno, $curlError));
} }
continue; continue;
} }
@@ -63,7 +63,6 @@ final class Util
return $curlResponse; return $curlResponse;
} }
return false; return false;
} }
} }