ExceptionAsString   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 12
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A getPhpVariables() 0 3 1
A __toString() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Provide\Error;
6
7
use BEAR\Package\Types;
8
use BEAR\Sunday\Extension\Router\RouterMatch as Request;
9
use Override;
10
use Stringable;
11
use Throwable;
12
13
use function date;
14
use function print_r;
15
use function sprintf;
16
17
use const DATE_RFC2822;
18
19
/** @psalm-import-type ServerArray from Types */
20
final class ExceptionAsString implements Stringable
21
{
22
    private string $string;
23
24
    public function __construct(Throwable $e, Request $request)
25
    {
26
        $eSummery = sprintf(
27
            "%s(%s)\n in file %s on line %s\n\n%s",
28
            $e::class,
29
            $e->getMessage(),
30
            $e->getFile(),
31
            $e->getLine(),
32
            $e->getTraceAsString(),
33
        );
34
35
        /** @var array<string, string> $_SERVER */ //phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.NoAssignment
36
        $this->string = sprintf("%s\n%s\n\n%s\n%s\n\n", date(DATE_RFC2822), (string) $request, $eSummery, $this->getPhpVariables($_SERVER));
37
    }
38
39
    #[Override]
40
    public function __toString(): string
41
    {
42
        return $this->string;
43
    }
44
45
    /** @param ServerArray $server */
0 ignored issues
show
Bug introduced by
The type BEAR\Package\Provide\Error\ServerArray was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
46
    private function getPhpVariables(array $server): string
47
    {
48
        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

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