Completed
Push — master ( d75d5a...4097cc )
by Abdullah
06:24
created

ZendeskMessage   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 204
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 56%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 0
dl 0
loc 204
ccs 28
cts 50
cp 0.56
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A __construct() 0 5 1
A subject() 0 6 1
A from() 0 9 1
A content() 0 7 1
A description() 0 6 1
A type() 0 9 2
A priority() 0 9 2
A status() 0 6 1
A visible() 0 6 1
A tags() 0 6 1
A toArray() 0 16 1
1
<?php
2
3
namespace NotificationChannels\Zendesk;
4
5
use NotificationChannels\Exception\CouldNotCreateMessage;
6
7
class ZendeskMessage
8
{
9
    /** @var string */
10
    protected $subject;
11
12
    /** @var array */
13
    protected $requester = [];
14
15
    /** @var string */
16
    protected $description = '';
17
18
    /** @var string */
19
    protected $type;
20
21
    /** @var string */
22
    protected $status = 'new';
23
24
    /** @var array */
25
    protected $tags = [];
26
27
    /** @var string */
28
    protected $content = '';
29
30
    /** @var bool */
31
    protected $isPublic = false;
32
33
    /** @var string */
34
    protected $priority = 'normal';
35
36
    /**
37
     * @param string $subject
38
     *
39
     * @return static
40
     */
41 1
    public static function create($subject = '', $description = '')
42
    {
43 1
        return new static($subject, $description);
44
    }
45
46
    /**
47
     * @param string $subject
48
     */
49 5
    public function __construct($subject = '', $description = '')
50
    {
51 5
        $this->subject = $subject;
52 5
        $this->content($description);
53 5
    }
54
55
    /**
56
     * Set the ticket subject.
57
     *
58
     * @param $subject
59
     *
60
     * @return $this
61
     */
62
    public function subject($subject)
63
    {
64
        $this->subject = $subject;
65
66
        return $this;
67
    }
68
69
    /**
70
     * Set the ticket customer name.
71
     *
72
     * @param string $name
73
     * @param string $email
74
     *
75
     * @return $this
76
     */
77 2
    public function from($name, $email)
78
    {
79 2
        $this->requester = [
80 2
            'name' => $name,
81 2
            'email' => $email,
82
        ];
83
84 2
        return $this;
85
    }
86
87
    /**
88
     * Set the content message.
89
     *
90
     * @param $content
91
     *
92
     * @return $this
93
     */
94 5
    public function content($content)
95
    {
96 5
        $this->description = $content;
97 5
        $this->content = $content;
98
99 5
        return $this;
100
    }
101
102
    /**
103
     * Set the description.
104
     *
105
     * @param string $description
106
     *
107
     * @return $this
108
     */
109
    public function description($description)
110
    {
111
        $this->description = $description;
112
113
        return $this;
114
    }
115
116
    /**
117
     * Set the ticket type.
118
     * Allowed values are problem, incident, question, or task.
119
     *
120
     * @param string $type
121
     *
122
     * @return $this
123
     */
124
    public function type($type)
125
    {
126
        if (! in_array($type, ['problem', 'incident', 'question', 'task'])) {
127
            throw CouldNotCreateMessage::invalidIndent($priority);
128
        }
129
        $this->type = $type;
130
131
        return $this;
132
    }
133
134
    /**
135
     * Set the ticket priority.
136
     * Allowed values are urgent, high, normal, or low.
137
     *
138
     * @param string $priority
139
     *
140
     * @return $this
141
     */
142
    public function priority($priority)
143
    {
144
        if (! in_array($priority, ['urgent', 'high', 'normal', 'low'])) {
145
            throw CouldNotCreateMessage::invalidPriority($priority);
146
        }
147
        $this->priority = $priority;
148
149
        return $this;
150
    }
151
152
    /**
153
     * Set the ticket status.
154
     * Allowed values are new, open, pending, hold, solved or closed.
155
     *
156
     * @return $this
157
     */
158
    public function status($status)
159
    {
160
        $this->status = $status;
161
162
        return $this;
163
    }
164
165
    /**
166
     * Set the message to be public.
167
     *
168
     * @return $this
169
     */
170 1
    public function visible()
171
    {
172 1
        $this->isPublic = true;
173
174 1
        return $this;
175
    }
176
177
    /**
178
     * Set an array of tags to add to the ticket.
179
     *
180
     * @param array $tags
181
     *
182
     * @return $this
183
     */
184
    public function tags(array $tags)
185
    {
186
        $this->tags = $tags;
187
188
        return $this;
189
    }
190
191
    /**
192
     * @return array
193
     */
194 5
    public function toArray()
195
    {
196
        return [
197 5
            'subject' => $this->subject,
198
            'comment' => [
199 5
                'body' => $this->content,
200 5
                'public' => $this->isPublic,
201
            ],
202 5
            'requester' => $this->requester,
203 5
            'description' => $this->description,
204 5
            'type' => $this->type,
205 5
            'status' => $this->status,
206 5
            'tags' => $this->tags,
207 5
            'priority' => $this->priority,
208
        ];
209
    }
210
}
211