IncidentRecord   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 3
dl 0
loc 139
rs 10
c 0
b 0
f 0

11 Methods

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