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

File::setSize()   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
class File implements FileInterface
6
{
7
    protected $name = '';
8
9
    protected $size = 0;
10
11
    protected $thumbUrl = '';
12
13
    protected $url = '';
14
15
    /**
16
     * File constructor
17
     */
18 9
    public function __construct($json = null)
19
    {
20 9
        $this->parseJson($json);
21 9
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26 9
    public function parseJson($json)
27
    {
28 9
        if (! $json) {
29 7
            return;
30
        }
31
32 3
        $this->name = $json['name'];
33 3
        $this->size = (int) $json['size'];
34 3
        $this->url = $json['url'];
35
36 3
        if (isset($json['thumb_url'])) {
37 3
            $this->thumbUrl = $json['thumb_url'];
38
        }
39 3
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44 1
    public function toJson()
45
    {
46
        $json = array(
47 1
            'name' => $this->name,
48 1
            'size' => $this->size,
49 1
            'url' => $this->url,
50
        );
51
52 1
        if ($this->thumbUrl) {
53
            $json['thumb_url'] = $this->thumbUrl;
54
        }
55
56 1
        return $json;
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62 2
    public function setName($name)
63
    {
64 2
        $this->name = $name;
65
66 2
        return $this;
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72 1
    public function getName()
73
    {
74 1
        return $this->name;
75
    }
76
77
    /**
78
     * @inheritdoc
79
     */
80 1
    public function setSize($size)
81
    {
82 1
        $this->size = (int) $size;
83
84 1
        return $this;
85
    }
86
87
    /**
88
     * @inheritdoc
89
     */
90 1
    public function getSize()
91
    {
92 1
        return $this->size;
93
    }
94
95
    /**
96
     * @inheritdoc
97
     */
98 1
    public function setThumbUrl($thumbUrl)
99
    {
100 1
        $this->thumbUrl = $thumbUrl;
101
102 1
        return $this;
103
    }
104
105
    /**
106
     * @inheritdoc
107
     */
108 1
    public function getThumbUrl()
109
    {
110 1
        return $this->thumbUrl;
111
    }
112
113
    /**
114
     * @inheritdoc
115
     */
116 2
    public function setUrl($url)
117
    {
118 2
        $this->url = $url;
119
120 2
        return $this;
121
    }
122
123
    /**
124
     * @inheritdoc
125
     */
126 1
    public function getUrl()
127
    {
128 1
        return $this->url;
129
    }
130
}
131