Completed
Pull Request — master (#17)
by
unknown
02:12
created

Message::setFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SolutionDrive\HipchatAPIv2Client\Model;
4
5
use SolutionDrive\HipchatAPIv2Client\Model\File;
6
use SolutionDrive\HipchatAPIv2Client\Model\FileInterface;
7
8
class Message implements MessageInterface
9
{
10
    protected $id = null;
11
12
    protected $color;
13
14
    protected $message;
15
16
    protected $notify;
17
18
    protected $messageFormat;
19
20
    protected $date = null;
21
22
    protected $from = '';
23
24
    protected $file = null;
25
26
    const COLOR_YELLOW = 'yellow';
27
    const COLOR_GREEN = 'green';
28
    const COLOR_RED = 'red';
29
    const COLOR_PURPLE = 'purple';
30
    const COLOR_GRAY = 'gray';
31
    const COLOR_RANDOM = 'random';
32
33
    const FORMAT_HTML = 'html';
34
    const FORMAT_TEXT = 'text';
35
36
    /**
37
     * Message constructor
38
     */
39 14
    public function __construct($json = null)
40
    {
41 14
        if ($json) {
42 1
            $this->parseJson($json);
43
        } else {
44 13
            $this->color = self::COLOR_YELLOW;
45 13
            $this->messageFormat = self::FORMAT_HTML;
46 13
            $this->message = '';
47 13
            $this->notify = false;
48
        }
49 14
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54 2
    public function parseJson($json)
55
    {
56 2
        $this->id = $json['id'];
57 2
        $this->from = is_array($json['from']) ? $json['from']['name'] : $json['from'];
58 2
        $this->message = $json['message'];
59 2
        $this->color = isset($json['color']) ? $json['color'] : null;
60 2
        $this->notify = isset($json['notify']) ? $json['notify'] : false;
61 2
        $this->messageFormat = isset($json['message_format']) ? $json['message_format'] : 'html';
62 2
        $this->date = $json['date'];
63 2
        $this->file = isset($json['file']) ? new File($json['file']) : null;
64 2
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69 1
    public function toJson()
70
    {
71 1
        $json = array();
72 1
        $json['id'] = $this->id;
73 1
        $json['from'] = $this->from;
74 1
        $json['color'] = $this->color;
75 1
        $json['message'] = $this->message;
76 1
        $json['notify'] = $this->notify;
77 1
        $json['message_format'] = $this->messageFormat;
78 1
        $json['date'] = $this->date;
79
80 1
        if ($this->file) {
81
            $json['file'] = $this->file->toJson();
82
        }
83
84 1
        return $json;
85
    }
86
87
    /**
88
     * @inheritdoc
89
     */
90 1
    public function setId($id)
91
    {
92 1
        $this->id = $id;
93
94 1
        return $this;
95
    }
96
97
    /**
98
     * @inheritdoc
99
     */
100 1
    public function getId()
101
    {
102 1
        return $this->id;
103
    }
104
105
    /**
106
     * @inheritdoc
107
     */
108 2
    public function setColor($color)
109
    {
110 2
        $this->color = $color;
111
112 2
        return $this;
113
    }
114
115
    /**
116
     * @inheritdoc
117
     */
118 1
    public function getColor()
119
    {
120 1
        return $this->color;
121
    }
122
123
    /**
124
     * @inheritdoc
125
     */
126 2
    public function setMessage($message)
127
    {
128 2
        $this->message = $message;
129
130 2
        return $this;
131
    }
132
133
    /**
134
     * @inheritdoc
135
     */
136 1
    public function getMessage()
137
    {
138 1
        return $this->message;
139
    }
140
141
    /**
142
     * @inheritdoc
143
     */
144 1
    public function setNotify($notify)
145
    {
146 1
        $this->notify = $notify;
147
148 1
        return $this;
149
    }
150
151
    /**
152
     * @inheritdoc
153
     */
154 1
    public function isNotify()
155
    {
156 1
        return $this->notify;
157
    }
158
159
    /**
160
     * @inheritdoc
161
     */
162 1
    public function setMessageFormat($messageFormat)
163
    {
164 1
        $this->messageFormat = $messageFormat;
165
166 1
        return $this;
167
    }
168
169
    /**
170
     * @inheritdoc
171
     */
172 1
    public function getMessageFormat()
173
    {
174 1
        return $this->messageFormat;
175
    }
176
177
    /**
178
     * @inheritdoc
179
     */
180
    public function setDate($date)
181
    {
182
        $this->date = $date;
183
184
        return $this;
185
    }
186
187
    /**
188
     * @inheritdoc
189
     */
190
    public function getDate()
191
    {
192
        return $this->date;
193
    }
194
195
    /**
196
     * @inheritdoc
197
     */
198 2
    public function setFrom($from)
199
    {
200 2
        $this->from = $from;
201
202 2
        return $this;
203
    }
204
205
    /**
206
     * @inheritdoc
207
     */
208 2
    public function getFrom()
209
    {
210 2
        return $this->from;
211
    }
212
213
    /**
214
     * @inheritdoc
215
     */
216 1
    public function setFile(FileInterface $file)
217
    {
218 1
        $this->file = $file;
219
220 1
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type SolutionDrive\HipchatAPIv2Client\Model\Message which is incompatible with the return type mandated by SolutionDrive\HipchatAPI...ageInterface::setFile() of SolutionDrive\HipchatAPI...ent\Model\FileInterface.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
221
    }
222
223
    /**
224
     * @inheritdoc
225
     */
226 1
    public function getFile()
227
    {
228 1
        return $this->file;
229
    }
230
}
231