Make global namespace in function calls explicit, use error_log to log

messages sent
This commit is contained in:
Joshua Ramon Enslin 2020-10-23 15:07:06 +02:00 committed by Stefan Rohde-Enslin
parent c13d06eccb
commit b1e86b94b9
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -62,8 +62,8 @@ final class MDErrorReporter {
final public function human_filesize(string $bytes, int $decimals = 2):string { final public function human_filesize(string $bytes, int $decimals = 2):string {
$size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB']; $size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB'];
$factor = floor((strlen($bytes) - 1) / 3); $factor = \floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . $size[$factor]; return \sprintf("%.{$decimals}f", $bytes / \pow(1024, $factor)) . $size[$factor];
} }
@ -90,17 +90,17 @@ final class MDErrorReporter {
$longestKey = 0; $longestKey = 0;
foreach ($toFormat as $key => $value) { foreach ($toFormat as $key => $value) {
if (strlen((string)$key) + (4 * $level) > $longestKey) $longestKey = strlen((string)$key) + (4 * $level); if (\strlen((string)$key) + (4 * $level) > $longestKey) $longestKey = \strlen((string)$key) + (4 * $level);
} }
foreach ($toFormat as $key => $value) { foreach ($toFormat as $key => $value) {
if (is_array($value)) { if (\is_array($value)) {
$msg .= $this->_formulateDebugMailSection((string)$key, $value, $level + 1); $msg .= $this->_formulateDebugMailSection((string)$key, $value, $level + 1);
} }
else if (is_object($value)) { else if (\is_object($value)) {
$msg .= sprintf("%-{$longestKey}s :: %s", $key, var_export($value, true)) . PHP_EOL; $msg .= \sprintf("%-{$longestKey}s :: %s", $key, \var_export($value, true)) . PHP_EOL;
} }
else { else {
$msg .= sprintf("%-{$longestKey}s :: %s", $key, (string)$value) . PHP_EOL; $msg .= \sprintf("%-{$longestKey}s :: %s", $key, (string)$value) . PHP_EOL;
} }
} }
$msg .= PHP_EOL; $msg .= PHP_EOL;
@ -117,9 +117,9 @@ final class MDErrorReporter {
final public function getAdditionalDebuggingInfo():array { final public function getAdditionalDebuggingInfo():array {
$output = [ $output = [
"Current memory usage" => $this->human_filesize((string)memory_get_usage()), "Current memory usage" => $this->human_filesize((string)\memory_get_usage()),
"Peak memory usage" => $this->human_filesize((string)memory_get_peak_usage()), "Peak memory usage" => $this->human_filesize((string)\memory_get_peak_usage()),
"Included / required files" => get_included_files(), "Included / required files" => \get_included_files(),
# "Allowed memory usage" => $this->human_filesize((string)ini_get("memory_limit")), # "Allowed memory usage" => $this->human_filesize((string)ini_get("memory_limit")),
]; ];
@ -158,7 +158,7 @@ final class MDErrorReporter {
$msg .= "$description" . PHP_EOL; $msg .= "$description" . PHP_EOL;
} }
$msg .= $this->_formulateDebugMailSection("Debug backtrace", debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT)); $msg .= $this->_formulateDebugMailSection("Debug backtrace", \debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT));
if (PHP_SAPI === 'cli') { if (PHP_SAPI === 'cli') {
echo $msg; echo $msg;
@ -216,7 +216,7 @@ final class MDErrorReporter {
*/ */
final public function sendErrorReport(Throwable $exception, string $recipient, string $addDesc = ""):void { final public function sendErrorReport(Throwable $exception, string $recipient, string $addDesc = ""):void {
$subject = get_class($exception) . ": " . $exception->getCode(); $subject = \get_class($exception) . ": " . $exception->getCode();
$description = $addDesc; $description = $addDesc;
@ -232,6 +232,8 @@ final class MDErrorReporter {
$additionalContextInfo $additionalContextInfo
); );
\error_log((string)$exception);
} }
/** /**