Completed
Pull Request — master (#3)
by Valentin
14:15
created

IncidentRecord::getExceptionCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spiral\Snapshotter\AggregationHandler\Database;
4
5
use Spiral\Models\Accessors\SqlTimestamp;
6
use Spiral\Models\Traits\TimestampsTrait;
7
use Spiral\ORM\Entities\Relations\HasOneRelation;
8
use Spiral\ORM\Record;
9
use Spiral\Snapshotter\AggregationHandler\Database\Types\IncidentStatus;
10
11
/**
12
 * Class Aggregation
13
 *
14
 * @property int            $id
15
 * @property SqlTimestamp   time_created
16
 * @property string         $exception_source
17
 * @property IncidentStatus $status
18
 * @property string         $exception_hash
19
 * @property string         $exception_teaser
20
 * @property string         $exception_classname
21
 * @property string         $exception_message
22
 * @property string         $exception_line
23
 * @property string         $exception_file
24
 * @property string         $exception_code
25
 * @property HasOneRelation $parent_snapshot
26
 * @property HasOneRelation $snapshot
27
 */
28
class IncidentRecord extends Record
29
{
30
    use TimestampsTrait;
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    const DATABASE = 'snapshots';
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    const SCHEMA = [
41
        //primary fields
42
        'id'                  => 'primary',
43
        'status'              => IncidentStatus::class,
44
45
        //exception fields
46
        'exception_hash'      => 'string',
47
        'exception_source'    => 'longText, nullable',
48
        'exception_teaser'    => 'string',
49
        'exception_classname' => 'string',
50
        'exception_message'   => 'string',
51
        'exception_line'      => 'int',
52
        'exception_file'      => 'string',
53
        'exception_code'      => 'int',
54
    ];
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    const SECURED = [
60
        'exception_source', //should be passed via gzencode setter
61
    ];
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    const INDEXES = [
67
        [self::INDEX, 'exception_hash'],
68
    ];
69
70
    /**
71
     * Suppress incident. Set according status and clean source.
72
     */
73
    public function suppress()
74
    {
75
        $this->status->setSuppressed();
76
        $this->exception_source = null;
77
    }
78
79
    /**
80
     * Delete override.
81
     */
82
    public function delete()
83
    {
84
        $this->status->setDeleted();
85
        $this->exception_source = null;
86
        $this->save();
87
    }
88
89
    /**
90
     * @return null|string
91
     */
92
    public function getExceptionSource()
93
    {
94
        $source = $this->exception_source;
95
        if (empty($source)) {
96
            return null;
97
        }
98
99
        return ($this->exception_source);
100
    }
101
102
    /**
103
     * @param string $source
104
     */
105
    public function setExceptionSource(string $source)
106
    {
107
        $this->exception_source = gzencode($source, 9);
108
    }
109
110
    /**
111
     * @return int
112
     */
113
    public function getExceptionCode(): int
114
    {
115
        return $this->exception_code;
116
    }
117
118
    /**
119
     * @return string
120
     */
121
    public function getExceptionHash(): string
122
    {
123
        return $this->exception_hash;
124
    }
125
126
    /**
127
     * @return string
128
     */
129
    public function getExceptionTeaser(): string
130
    {
131
        return $this->exception_teaser;
132
    }
133
134
    /**
135
     * @return string
136
     */
137
    public function getExceptionClass(): string
138
    {
139
        return $this->exception_classname;
140
    }
141
142
    /**
143
     * @return string
144
     */
145
    public function getExceptionMessage(): string
146
    {
147
        return $this->exception_message;
148
    }
149
150
    /**
151
     * @return int
152
     */
153
    public function getExceptionLine(): int
154
    {
155
        return $this->exception_line;
156
    }
157
158
    /**
159
     * @return string
160
     */
161
    public function getExceptionFile(): string
162
    {
163
        return $this->exception_file;
164
    }
165
}