ExceptionAsString   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A __toString() 0 3 1
A getPhpVariables() 0 3 1
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 Stringable;
9
use Throwable;
10
11
use function date;
12
use function print_r;
13
use function sprintf;
14
15
use const DATE_RFC2822;
16
17
final class ExceptionAsString implements Stringable
18
{
19
    private string $string;
20
21
    public function __construct(Throwable $e, Request $request)
22
    {
23
        $eSummery = sprintf(
24
            "%s(%s)\n in file %s on line %s\n\n%s",
25
            $e::class,
26
            $e->getMessage(),
27
            $e->getFile(),
28
            $e->getLine(),
29
            $e->getTraceAsString(),
30
        );
31
32
        /** @var array<string, string> $_SERVER */ //phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.NoAssignment
33
        $this->string = sprintf("%s\n%s\n\n%s\n%s\n\n", date(DATE_RFC2822), (string) $request, $eSummery, $this->getPhpVariables($_SERVER));
34
    }
35
36
    public function __toString(): string
37
    {
38
        return $this->string;
39
    }
40
41
    /** @param array<string, mixed> $server */
42
    private function getPhpVariables(array $server): string
43
    {
44
        return sprintf("\nPHP Variables\n\n\$_SERVER => %s", print_r($server, true)); // @codeCoverageIgnore
0 ignored issues
show
Bug introduced by
It seems like print_r($server, true) can also be of type true; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
        return sprintf("\nPHP Variables\n\n\$_SERVER => %s", /** @scrutinizer ignore-type */ print_r($server, true)); // @codeCoverageIgnore
Loading history...
45
    }
46
}
47