Completed
Push — 1.x ( 64141c...67746d )
by Akihito
14s queued 11s
created

ExceptionAsString::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * This file is part of the BEAR.Package package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\Package\Provide\Error;
8
9
use BEAR\Sunday\Extension\Router\RouterMatch as Request;
10
11
final class ExceptionAsString
12
{
13
    /**
14
     * @var string
15
     */
16
    private $string;
17
18 1
    public function __construct(\Exception $e, Request $request)
19
    {
20 1
        $eSummery = sprintf(
21 1
            "%s(%s)\n in file %s on line %s\n\n%s",
22 1
            \get_class($e),
23 1
            $e->getMessage(),
24 1
            $e->getFile(),
25 1
            $e->getLine(),
26 1
            $e->getTraceAsString()
27
        );
28
29 1
        $this->string = sprintf("%s\n%s\n\n%s\n%s\n\n", date(DATE_RFC2822), $request, $eSummery, $this->getPhpVariables($_SERVER));
30 1
    }
31
32 1
    public function __toString()
33
    {
34 1
        return $this->string;
35
    }
36
37
    private function getPhpVariables(array $server) : string
38
    {
39
        return sprintf("\nPHP Variables\n\n\$_SERVER => %s", print_r($server, true)); // @codeCoverageIgnore
40
    }
41
}
42