Room   A
last analyzed

Complexity

Total Complexity 32

Size/Duplication

Total Lines 297
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 297
ccs 96
cts 96
cp 1
rs 9.6
c 0
b 0
f 0
wmc 32

27 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A setPrivacy() 0 4 1
A getGuestAccessUrl() 0 3 1
A getPrivacy() 0 3 1
A getLinks() 0 3 1
A setCreated() 0 4 1
A setArchived() 0 4 1
A setParticipants() 0 4 1
A setGuestAccessible() 0 4 1
A getCreated() 0 3 1
A getXmppJid() 0 3 1
A setXmppJid() 0 4 1
A getTopic() 0 3 1
A getName() 0 3 1
A setId() 0 4 1
A setOwner() 0 4 1
A getOwner() 0 3 1
A setName() 0 4 1
A getId() 0 3 1
A setTopic() 0 4 1
A setGuestAccessUrl() 0 4 1
A isGuestAccessible() 0 3 1
A isArchived() 0 3 1
A setLinks() 0 4 1
A getParticipants() 0 3 1
A toJson() 0 19 3
A parseJson() 0 20 3
1
<?php
2
3
namespace SolutionDrive\HipchatAPIv2Client\Model;
4
5
class Room implements RoomInterface
6
{
7
    protected $id;
8
9
    protected $xmppJid;
10
11
    //protected $statistics;
12
13
    protected $name;
14
15
    protected $links;
16
17
    protected $created;
18
19
    protected $archived;
20
21
    protected $privacy;
22
23
    protected $guestAccessible;
24
25
    protected $topic;
26
27
    protected $participants;
28
29
    protected $owner;
30
31
    protected $guestAccessUrl;
32
33
    /**
34
     * Builds a room object from server response if json given, otherwise creates an empty object
35
     *
36
     * @param array $json json_decoded response in json given by the server
37
     *
38
     * @return self
39
     */
40 19
    public function __construct($json = null)
41
    {
42 19
        if ($json) {
43 2
            $this->parseJson($json);
44
        } else {
45 17
            $this->guestAccessible = false;
46 17
            $this->privacy = 'public';
47
        }
48 19
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53 4
    public function parseJson($json)
54
    {
55 4
        $this->id = $json['id'];
56 4
        $this->name = $json['name'];
57 4
        $this->links = $json['links'];
58
59 4
        if (isset($json['xmpp_jid'])) {
60 2
            $this->xmppJid = $json['xmpp_jid'];
61
            //Statistics need to be implemented
62 2
            $this->created = new \DateTime($json['created']);
63 2
            $this->archived = $json['is_archived'];
64 2
            $this->privacy = $json['privacy'];
65 2
            $this->guestAccessible = $json['is_guest_accessible'];
66 2
            $this->topic = $json['topic'];
67 2
            $this->participants = array();
68 2
            foreach ($json['participants'] as $participant) {
69 1
                $this->participants[] = new User($participant);
70
            }
71 2
            $this->owner = new User($json['owner']);
72 2
            $this->guestAccessUrl = $json['guest_access_url'];
73
        }
74 4
    }
75
76
    /**
77
     * @inheritdoc
78
     */
79 2
    public function toJson()
80
    {
81 2
        $json = array();
82
83 2
        $json['name'] = $this->getName();
84 2
        $json['privacy'] = $this->getPrivacy();
85
        //Parameters for PUT call (Room already exists)
86 2
        if ($this->getId()) {
87 1
            $json['is_archived'] = $this->isArchived();
88 1
            $json['is_guest_accessible'] = $this->isGuestAccessible();
89 1
            $json['topic'] = $this->getTopic();
90 1
            $json['owner'] = array('id' => $this->getOwner()->getId());
91
        } else { //Paramters for POST call
92 1
            $json['guest_access'] = $this->isGuestAccessible();
93 1
            if ($this->getOwner()) {
94 1
                $json['owner_user_id'] = $this->getOwner()->getId();
95
            }
96
        }
97 2
        return $json;
98
    }
99
100
    /**
101
     * @inheritdoc
102
     */
103 2
    public function setId($id)
104
    {
105 2
        $this->id = $id;
106 2
        return $this;
107
    }
108
109
    /**
110
     * @inheritdoc
111
     */
112 5
    public function getId()
113
    {
114 5
        return $this->id;
115
    }
116
117
    /**
118
     * @inheritdoc
119
     */
120 1
    public function setXmppJid($xmppJid)
121
    {
122 1
        $this->xmppJid = $xmppJid;
123 1
        return $this;
124
    }
125
126
    /**
127
     * @inheritdoc
128
     */
129 1
    public function getXmppJid()
130
    {
131 1
        return $this->xmppJid;
132
    }
133
134
    /**
135
     * @inheritdoc
136
     */
137 3
    public function setName($name)
138
    {
139 3
        $this->name = $name;
140 3
        return $this;
141
    }
142
143
    /**
144
     * @inheritdoc
145
     */
146 3
    public function getName()
147
    {
148 3
        return $this->name;
149
    }
150
151
    /**
152
     * @inheritdoc
153
     */
154 1
    public function setLinks($links)
155
    {
156 1
        $this->links = $links;
157 1
        return $this;
158
    }
159
160
    /**
161
     * @inheritdoc
162
     */
163 1
    public function getLinks()
164
    {
165 1
        return $this->links;
166
    }
167
168
    /**
169
     * @inheritdoc
170
     */
171 1
    public function setCreated($created)
172
    {
173 1
        $this->created = $created;
174 1
        return $this;
175
    }
176
177
    /**
178
     * @inheritdoc
179
     */
180 1
    public function getCreated()
181
    {
182 1
        return $this->created;
183
    }
184
185
    /**
186
     * @inheritdoc
187
     */
188 2
    public function setArchived($archived)
189
    {
190 2
        $this->archived = $archived;
191 2
        return $this;
192
    }
193
194
    /**
195
     * @inheritdoc
196
     */
197 2
    public function isArchived()
198
    {
199 2
        return $this->archived;
200
    }
201
202
    /**
203
     * @inheritdoc
204
     */
205 3
    public function setPrivacy($privacy)
206
    {
207 3
        $this->privacy = $privacy;
208 3
        return $this;
209
    }
210
211
    /**
212
     * @inheritdoc
213
     */
214 3
    public function getPrivacy()
215
    {
216 3
        return $this->privacy;
217
    }
218
219
    /**
220
     * @inheritdoc
221
     */
222 3
    public function setGuestAccessible($guestAccessible)
223
    {
224 3
        $this->guestAccessible = $guestAccessible;
225 3
        return $this;
226
    }
227
228
    /**
229
     * @inheritdoc
230
     */
231 4
    public function isGuestAccessible()
232
    {
233 4
        return $this->guestAccessible;
234
    }
235
236
    /**
237
     * @inheritdoc
238
     */
239 2
    public function setTopic($topic)
240
    {
241 2
        $this->topic = $topic;
242 2
        return $this;
243
    }
244
245
    /**
246
     * @inheritdoc
247
     */
248 2
    public function getTopic()
249
    {
250 2
        return $this->topic;
251
    }
252
253
    /**
254
     * @inheritdoc
255
     */
256 1
    public function setParticipants($participants)
257
    {
258 1
        $this->participants = $participants;
259 1
        return $this;
260
    }
261
262
    /**
263
     * @inheritdoc
264
     */
265 1
    public function getParticipants()
266
    {
267 1
        return $this->participants;
268
    }
269
270
    /**
271
     * @inheritdoc
272
     */
273 3
    public function setOwner($owner)
274
    {
275 3
        $this->owner = $owner;
276 3
        return $this;
277
    }
278
279
    /**
280
     * @inheritdoc
281
     */
282 4
    public function getOwner()
283
    {
284 4
        return $this->owner;
285
    }
286
287
    /**
288
     * @inheritdoc
289
     */
290 1
    public function setGuestAccessUrl($guestAccessUrl)
291
    {
292 1
        $this->guestAccessUrl = $guestAccessUrl;
293 1
        return $this;
294
    }
295
296
    /**
297
     * @inheritdoc
298
     */
299 1
    public function getGuestAccessUrl()
300
    {
301 1
        return $this->guestAccessUrl;
302
    }
303
}
304