Passed
Push — master ( e24ab0...9e1161 )
by Kirill
03:14
created

Snapshot::getMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Snapshots;
13
14
/**
15
 * Carries information about specific error.
16
 */
17
final class Snapshot implements SnapshotInterface
18
{
19
    /** @var string */
20
    private $id;
21
22
    /** @var \Throwable */
23
    private $exception;
24
25
    /**
26
     * @param string     $id
27
     * @param \Throwable $exception
28
     */
29
    public function __construct(string $id, \Throwable $exception)
30
    {
31
        $this->id = $id;
32
        $this->exception = $exception;
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function getID(): string
39
    {
40
        return $this->id;
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46
    public function getException(): \Throwable
47
    {
48
        return $this->exception;
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public function getMessage(): string
55
    {
56
        return sprintf(
57
            '%s: %s in %s at line %s',
58
            get_class($this->exception),
59
            $this->exception->getMessage(),
60
            $this->exception->getFile(),
61
            $this->exception->getLine()
62
        );
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68
    public function describe(): array
69
    {
70
        return [
71
            'error'    => $this->getMessage(),
72
            'location' => [
73
                'file' => $this->exception->getFile(),
74
                'line' => $this->exception->getLine()
75
            ],
76
            'trace'    => $this->exception->getTrace()
77
        ];
78
    }
79
}
80