Completed
Push — master ( 284f9e...bc74a2 )
by Luke
06:35 queued 01:43
created

Event::addLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * PagerDuty v2 Events API Library.
4
 *
5
 * @author    Luke Waite <[email protected]>
6
 * @copyright 2017 Luke Waite
7
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
8
 *
9
 * @link      https://github.com/lukewaite/pagerduty
10
 */
11
12
namespace LukeWaite\PagerDuty;
13
14
class Event
15
{
16
    protected $event;
17
18 8
    public function __construct($event = [])
19
    {
20 8
        foreach (array_keys($event) as $key) {
21 4
            $this->event[$key] = $event[$key];
22 8
        }
23
24 8
        $this->setDefaults();
25 8
    }
26
27 8
    protected function setDefaults()
28
    {
29 8
        if (!isset($this->event['payload']['severity'])) {
30 8
            $this->event['payload']['severity'] = 'critical';
31 8
        }
32
33
34 8
        if (!isset($this->event['payload']['source'])) {
35 4
            $this->event['payload']['source'] = gethostname();
36 4
        }
37 8
    }
38
39 2
    public function setRoutingKey($value)
40
    {
41 2
        return $this->setMeta('routing_key', $value);
42
    }
43
44
    public function resolve()
45
    {
46
        // TODO: Implement resolve
47
    }
48
49
    public function trigger()
50
    {
51
        // TODO: Implement trigger
52
    }
53
54
    public function acknowledge()
55
    {
56
        // TODO: Implement acknowledge
57
    }
58
59 2
    public function setDedupKey($key)
60
    {
61 2
        return $this->setMeta('dedup_key', $key);
62
    }
63
64 2
    public function setSummary($value)
65
    {
66 2
        return $this->setPayload('summary', $value);
67
    }
68
69 2
    public function setSource($value)
70
    {
71 2
        return $this->setPayload('source', $value);
72
    }
73
74 2
    public function setSeverity($value)
75
    {
76 2
        return $this->setPayload('severity', $value);
77
    }
78
79 2
    public function setTimestamp($value)
80
    {
81 2
        return $this->setPayload('timestamp', $value);
82
    }
83
84 2
    public function setComponent($value)
85
    {
86 2
        return $this->setPayload('component', $value);
87
    }
88
89 2
    public function setGroup($value)
90
    {
91 2
        return $this->setPayload('group', $value);
92
    }
93
94 2
    public function setClass($value)
95
    {
96 2
        return $this->setPayload('class', $value);
97
    }
98
99 2
    public function addCustomDetail($key, $value)
100
    {
101 2
        $this->event["payload"]["custom_details"][$key] = $value;
102
103 2
        return $this;
104
    }
105
106
    public function addLink()
107
    {
108
        // TODO: Implement addLink
109
    }
110
111
    public function addImage()
112
    {
113
        // TODO: Implement addImage
114
    }
115
116 2
    protected function setPayload($key, $value)
117
    {
118 2
        $this->event["payload"][$key] = $value;
119
120 2
        return $this;
121
    }
122
123 2
    protected function setMeta($key, $value)
124
    {
125 2
        $this->event[$key] = $value;
126
127 2
        return $this;
128
    }
129
130 8
    public function toArray()
131
    {
132 8
        return $this->event;
133
    }
134
135
    public function toJson()
136
    {
137
        return json_encode($this->event);
138
    }
139
}
140