ExceptionAsString::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Provide\Error;
6
7
use BEAR\Sunday\Extension\Router\RouterMatch as Request;
8
use Throwable;
9
10
use function date;
11
use function get_class;
12
use function print_r;
13
use function sprintf;
14
15
use const DATE_RFC2822;
16
17
final class ExceptionAsString
18
{
19
    /** @var string */
20
    private $string;
21
22
    public function __construct(Throwable $e, Request $request)
23
    {
24
        $eSummery = sprintf(
25
            "%s(%s)\n in file %s on line %s\n\n%s",
26
            get_class($e),
27
            $e->getMessage(),
28
            $e->getFile(),
29
            $e->getLine(),
30
            $e->getTraceAsString()
31
        );
32
33
        /** @var array<string, string> $_SERVER */ //phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.NoAssignment
34
        $this->string = sprintf("%s\n%s\n\n%s\n%s\n\n", date(DATE_RFC2822), (string) $request, $eSummery, $this->getPhpVariables($_SERVER));
35
    }
36
37
    public function __toString(): string
38
    {
39
        return $this->string;
40
    }
41
42
    /**
43
     * @param array<string, mixed> $server
44
     */
45
    private function getPhpVariables(array $server): string
46
    {
47
        return sprintf("\nPHP Variables\n\n\$_SERVER => %s", print_r($server, true)); // @codeCoverageIgnore
48
    }
49
}
50