Completed
Push — master ( 5decb7...aee104 )
by Thibaud
14:37 queued 11:26
created

Record::getTechnicalInformation()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 10
ccs 5
cts 7
cp 0.7143
rs 9.4285
cc 3
eloc 5
nc 4
nop 0
crap 3.2098
1
<?php
2
3
/*
4
 * This file is part of Phraseanet SDK.
5
 *
6
 * (c) Alchemy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhraseanetSDK\Entity;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
16
class Record
17
{
18
    /**
19
     * @param \stdClass[] $values
20
     * @return Record[]
21
     */
22 1
    public static function fromList(array $values)
23
    {
24 1
        $records = array();
25
26 1
        foreach ($values as $value) {
27 1
            $records[] = self::fromValue($value);
28 1
        }
29
30 1
        return $records;
31
    }
32
33
    /**
34
     * @param \stdClass $value
35
     * @return Record
36
     */
37 6
    public static function fromValue(\stdClass $value)
38
    {
39 6
        return new self($value);
40
    }
41
42
    /**
43
     * @var \stdClass
44
     */
45
    protected $source;
46
47
    /**
48
     * @var \DateTimeInterface
49
     */
50
    protected $updatedOn;
51
52
    /**
53
     * @var \DateTimeInterface
54
     */
55
    protected $createdOn;
56
57
    /**
58
     * @var Subdef
59
     */
60
    protected $thumbnail;
61
62
    /**
63
     * @var Technical[]
64
     */
65
    protected $technicalInformation;
66
67
    /**
68
     * @var Metadata[]
69
     */
70
    protected $metadata;
71
72
    /**
73
     * @var Subdef[]
74
     */
75
    protected $subdefs;
76
77
    /**
78
     * @var RecordStatus[]
79
     */
80
    protected $status;
81
82
    /**
83
     * @var RecordCaption[]
84
     */
85
    protected $caption;
86
87
    /**
88
     * @param \stdClass $source
89
     */
90 6
    public function __construct(\stdClass $source)
91
    {
92 6
        $this->source = $source;
93 6
    }
94
95
    /**
96
     * @return \stdClass
97
     */
98
    public function getRawData()
99
    {
100
        return $this->source;
101
    }
102
103
    /**
104
     * Get unique id
105
     *
106
     * @return string
107
     */
108 6
    public function getId()
109
    {
110 6
        return $this->getDataboxId() . '_' . $this->getRecordId();
111
    }
112
113
    /**
114
     * Get the record id
115
     *
116
     * @return integer
117
     */
118 6
    public function getRecordId()
119
    {
120 6
        return $this->source->record_id;
121
    }
122
123
    /**
124
     * Get the databox id
125
     *
126
     * @return integer
127
     */
128 6
    public function getDataboxId()
129
    {
130 6
        return $this->source->databox_id;
131
    }
132
133
    /**
134
     * Get the base id.
135
     *
136
     * @return integer
137
     */
138
    public function getBaseId()
139
    {
140
        return $this->source->base_id;
141
    }
142
143
    /**
144
     * Get the record title
145
     *
146
     * @return string
147
     */
148 6
    public function getTitle()
149
    {
150 6
        return $this->source->title;
151
    }
152
153
    /**
154
     * Get the record mime type
155
     *
156
     * @return string
157
     */
158 6
    public function getMimeType()
159
    {
160 6
        return $this->source->mime_type;
161
    }
162
163
    /**
164
     * Get the record original name
165
     *
166
     * @return string
167
     */
168 6
    public function getOriginalName()
169
    {
170 6
        return $this->source->original_name;
171
    }
172
173
    /**
174
     * Last updated date
175
     *
176
     * @return \DateTime
177
     */
178 6
    public function getUpdatedOn()
179
    {
180 6
        return $this->updatedOn ?: $this->updatedOn = new \DateTime($this->source->updated_on);
181
    }
182
183
    /**
184
     * Creation date
185
     *
186
     * @return \DateTime
187
     */
188 6
    public function getCreatedOn()
189
    {
190 6
        return $this->createdOn ?: $this->createdOn = new \DateTime($this->source->created_on);
191
    }
192
193
    /**
194
     * Get the record collection id
195
     *
196
     * @return integer
197
     */
198 6
    public function getCollectionId()
199
    {
200 6
        return $this->source->collection_id;
201
    }
202
203
    /**
204
     * Get the record SHA256 hash
205
     *
206
     * @return string
207
     */
208 6
    public function getSha256()
209
    {
210 6
        return $this->source->sha256;
211
    }
212
213
    /**
214
     * Return the thumbnail of the record as a PhraseanetSDK\Entity\Subdef object
215
     * if the thumbnail exists null otherwise
216
     *
217
     * @return Subdef|null
218
     */
219 6
    public function getThumbnail()
220
    {
221 6
        if (! isset($this->source->thumbnail)) {
222 1
            return null;
223
        }
224
225 5
        return $this->thumbnail ?: $this->thumbnail = Subdef::fromValue($this->source->thumbnail);
226
    }
227
228
    /**
229
     * Get the Record phraseaType IMAGE|VIDEO|DOCUMENT etc..
230
     *
231
     * @return string
232
     */
233 6
    public function getPhraseaType()
234
    {
235 6
        return $this->source->phrasea_type;
236
    }
237
238
    /**
239
     * Get the record UUID
240
     *
241
     * @return string
242
     */
243 6
    public function getUuid()
244
    {
245 6
        return $this->source->uuid;
246
    }
247
248
    /**
249
     * Get a collection of Phraseanet\Entity\Technical data objects
250
     *
251
     * @return ArrayCollection|Technical[]
252
     */
253 6
    public function getTechnicalInformation()
254
    {
255 6
        if (! isset($this->source->technical_informations)) {
256
            $this->technicalInformation = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type array<integer,object<Phr...tSDK\Entity\Technical>> of property $technicalInformation.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
257
        }
258
259 6
        return $this->technicalInformation ?: new ArrayCollection(Technical::fromList(
260 6
            $this->source->technical_informations
261 6
        ));
262
    }
263
264
    /**
265
     * Return a collection of PhraseanetSDK\Entity\Subdef for the record
266
     *
267
     * @return ArrayCollection|Subdef[]
268
     */
269
    public function getSubdefs()
270
    {
271
        if (! isset($this->source->subdefs)) {
272
            $this->subdefs = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type array<integer,object<Phr...anetSDK\Entity\Subdef>> of property $subdefs.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
273
        }
274
275
        return $this->subdefs ?: new ArrayCollection(Subdef::fromList($this->source->subdefs));
276
    }
277
278
    /**
279
     * @return RecordStatus[]|ArrayCollection
280
     */
281
    public function getStatus()
282
    {
283
        if (! isset($this->source->status)) {
284
            $this->status = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type array<integer,object<Phr...K\Entity\RecordStatus>> of property $status.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
285
        }
286
287
        return $this->status ?: new ArrayCollection(RecordStatus::fromList($this->source->status));
288
    }
289
290
    /**
291
     * @return RecordCaption[]|ArrayCollection
292
     */
293
    public function getCaption()
294
    {
295
        if (! isset($this->source->caption)) {
296
            $this->caption = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type array<integer,object<Phr...\Entity\RecordCaption>> of property $caption.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
297
        }
298
299
        return $this->caption ?: new ArrayCollection(RecordCaption::fromList($this->source->caption));
300
    }
301
302
    /**
303
     * @return Metadata[]|ArrayCollection
304
     */
305
    public function getMetadata()
306
    {
307
        if (! isset($this->source->metadata)) {
308
            $this->metadata = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type array<integer,object<Phr...etSDK\Entity\Metadata>> of property $metadata.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
309
        }
310
311
        return $this->metadata ?: new ArrayCollection(Metadata::fromList($this->source->metadata));
312
    }
313
}
314