Completed
Push — master ( 1baee3...d07a0e )
by Luke
04:04
created

PagerDutyMessage::setSource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.125

Importance

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