Statement::createFromArray()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 14
nc 4
nop 1
1
<?php
2
3
namespace Happyr\ApiClient\Model\Statement;
4
5
use Happyr\ApiClient\Model\CreatableFromArray;
6
7
/**
8
 * @author Tobias Nyholm <[email protected]>
9
 */
10
final class Statement implements CreatableFromArray
11
{
12
    const TYPE_STRING = 'string';
13
    const TYPE_IMAGE = 'image';
14
    const SECTION_PERSONALITY = 'personality';
15
    const SECTION_INTELLIGENCE = 'intelligence';
16
17
    /**
18
     * @var string
19
     */
20
    private $id;
21
22
    /**
23
     * Has a value if $type="text".
24
     *
25
     * @var string|null
26
     */
27
    private $sentence;
28
29
    /**
30
     * Has a value if $type="image".
31
     *
32
     * @var string|null
33
     */
34
    private $image;
35
36
    /**
37
     * @var array
38
     */
39
    private $assessments;
40
41
    /**
42
     * @var int
43
     */
44
    private $progress;
45
46
    /**
47
     * @var string
48
     */
49
    private $postUrl;
50
51
    /**
52
     * @var string
53
     */
54
    private $fullPostUrl;
55
56
    /**
57
     * @var string
58
     */
59
    private $section;
60
61
    /**
62
     * @var string
63
     */
64
    private $type;
65
66
    /**
67
     * @param string $id
68
     */
69
    private function __construct($id)
70
    {
71
        $this->id = $id;
72
    }
73
74
    /**
75
     * @param array $data
76
     *
77
     * @return Statement|null
78
     */
79
    public static function createFromArray(array $data)
80
    {
81
        $data = isset($data['data']) ? $data['data'] : [];
82
        if (empty($data)) {
83
            return null;
84
        }
85
86
        $statement = new self($data['id']);
87
        $statement->setSentence(isset($data['sentence']) ? $data['sentence'] : null);
88
        $statement->setImage(isset($data['image']) ? $data['image'] : null);
89
        $statement->setAssessments($data['assessments']);
90
        $statement->setProgress($data['progress']);
91
        $statement->setPostUrl($data['post_url']);
92
        $statement->setFullPostUrl($data['full_post_url']);
93
        $statement->setSection($data['section']);
94
        $statement->setType($data['type']);
95
96
        return $statement;
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function getId()
103
    {
104
        return $this->id;
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    public function getSentence()
111
    {
112
        return $this->sentence;
113
    }
114
115
    /**
116
     * @param string $sentence
117
     */
118
    private function setSentence($sentence)
119
    {
120
        $this->sentence = $sentence;
121
    }
122
123
    /**
124
     * @return null|string
125
     */
126
    public function getImage()
127
    {
128
        return $this->image;
129
    }
130
131
    /**
132
     * @param null|string $image
133
     */
134
    public function setImage($image)
135
    {
136
        $this->image = $image;
137
    }
138
139
    /**
140
     * @return array
141
     */
142
    public function getAssessments()
143
    {
144
        return $this->assessments;
145
    }
146
147
    /**
148
     * @param array $assessments
149
     */
150
    private function setAssessments($assessments)
151
    {
152
        $this->assessments = $assessments;
153
    }
154
155
    /**
156
     * @return int
157
     */
158
    public function getProgress()
159
    {
160
        return $this->progress;
161
    }
162
163
    /**
164
     * @param int $progress
165
     */
166
    private function setProgress($progress)
167
    {
168
        $this->progress = $progress;
169
    }
170
171
    /**
172
     * @return string
173
     */
174
    public function getPostUrl()
175
    {
176
        return $this->postUrl;
177
    }
178
179
    /**
180
     * @param string $postUrl
181
     */
182
    private function setPostUrl($postUrl)
183
    {
184
        $this->postUrl = $postUrl;
185
    }
186
187
    /**
188
     * @return string
189
     */
190
    public function getFullPostUrl()
191
    {
192
        return $this->fullPostUrl;
193
    }
194
195
    /**
196
     * @param string $fullPostUrl
197
     */
198
    private function setFullPostUrl($fullPostUrl)
199
    {
200
        $this->fullPostUrl = $fullPostUrl;
201
    }
202
203
    /**
204
     * @return string
205
     */
206
    public function getSection()
207
    {
208
        return $this->section;
209
    }
210
211
    /**
212
     * @param string $section
213
     */
214
    private function setSection($section)
215
    {
216
        $this->section = $section;
217
    }
218
219
    /**
220
     * @return string
221
     */
222
    public function getType()
223
    {
224
        return $this->type;
225
    }
226
227
    /**
228
     * @param string $type
229
     */
230
    private function setType($type)
231
    {
232
        $this->type = $type;
233
    }
234
}
235