Completed
Push — master ( 60ea6b...a5615b )
by Luke
04:21
created

PagerDutyMessage::setMeta()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace NotificationChannels\PagerDuty;
4
5
use Illuminate\Support\Arr;
6
7
class PagerDutyMessage
8
{
9
    const EVENT_TRIGGER = 'trigger';
10
    const EVENT_RESOLVE = 'resolve';
11
12
    protected $payload = [];
13
    protected $meta = [];
14
15 66
    public static function create()
16
    {
17 66
        return new static();
18
    }
19
20 66
    public function __construct()
21
    {
22 66
        Arr::set($this->meta, 'event_action', self::EVENT_TRIGGER);
23
24 66
        Arr::set($this->payload, 'source', gethostname());
25 66
        Arr::set($this->payload, 'severity', 'critical');
26 66
    }
27
28 66
    public function setRoutingKey($value)
29
    {
30 66
        return $this->setMeta('routing_key', $value);
31
    }
32
33 6
    public function resolve()
34
    {
35 6
        return $this->setMeta('event_action', self::EVENT_RESOLVE);
36
    }
37
38 12
    public function setDedupKey($key)
39
    {
40 12
        return $this->setMeta('dedup_key', $key);
41
    }
42
43 24
    public function setSummary($value)
44
    {
45 24
        return $this->setPayload('summary', $value);
46
    }
47
48 60
    public function setSource($value)
49
    {
50 60
        return $this->setPayload('source', $value);
51
    }
52
53 6
    public function setSeverity($value)
54
    {
55 6
        return $this->setPayload('severity', $value);
56
    }
57
58 6
    public function setTimestamp($value)
59
    {
60 6
        return $this->setPayload('timestamp', $value);
61
    }
62
63 6
    public function setComponent($value)
64
    {
65 6
        return $this->setPayload('component', $value);
66
    }
67
68 6
    public function setGroup($value)
69
    {
70 6
        return $this->setPayload('group', $value);
71
    }
72
73 6
    public function setClass($value)
74
    {
75 6
        return $this->setPayload('class', $value);
76
    }
77
78 6
    public function addCustomDetail($key, $value)
79
    {
80 6
        return $this->setPayload("custom_details.$key", $value);
81
    }
82
83 66
    protected function setPayload($key, $value)
84
    {
85 66
        Arr::set($this->payload, $key, $value);
86
87 66
        return $this;
88
    }
89
90 66
    protected function setMeta($key, $value)
91
    {
92 66
        Arr::set($this->meta, $key, $value);
93
94 66
        return $this;
95
    }
96
97 66
    public function toArray()
98
    {
99 66
        return Arr::collapse([$this->meta, ['payload' => $this->payload]]);
100
    }
101
}
102