ExceptionAsString::getPhpVariables()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 1
crap 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 Override;
9
use Stringable;
10
use Throwable;
11
12
use function date;
13
use function print_r;
14
use function sprintf;
15
16 1
use const DATE_RFC2822;
17
18 1
final class ExceptionAsString implements Stringable
19 1
{
20 1
    private string $string;
21 1
22 1
    public function __construct(Throwable $e, Request $request)
23 1
    {
24 1
        $eSummery = sprintf(
25
            "%s(%s)\n in file %s on line %s\n\n%s",
26
            $e::class,
27 1
            $e->getMessage(),
28 1
            $e->getFile(),
29
            $e->getLine(),
30 1
            $e->getTraceAsString(),
31
        );
32 1
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
    #[Override]
38
    public function __toString(): string
39
    {
40
        return $this->string;
41
    }
42
43
    /** @param array<string, mixed> $server */
44
    private function getPhpVariables(array $server): string
45
    {
46
        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

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