Completed
Push — master ( 2994aa...19d116 )
by Patrick
08:28
created

MediaInfo::setMediaMetadata()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 13
cp 0
rs 9.7333
c 0
b 0
f 0
cc 4
nc 4
nop 0
crap 20
1
<?php
2
namespace Dropbox\Models;
3
4
class MediaInfo extends BaseModel
5
{
6
7
    /**
8
     * Indicate the photo/video is still under processing
9
     * and metadata is not available yet.
10
     *
11
     * @var bool
12
     */
13
    protected $pending = false;
14
15
    /**
16
     * MediaMetadata
17
     *
18
     * @var \Dropbox\Models\MediaMetadata
19
     */
20
    protected $mediaMetadata;
21
22
23
    /**
24
     * Create a new MediaInfo instance
25
     *
26
     * @param array $data
27
     */
28
    public function __construct(array $data)
29
    {
30
        parent::__construct($data);
31
        $this->pending = $this->getDataProperty('pending');
32
        $this->setMediaMetadata();
33
    }
34
35
    /**
36
     * Set Media Metadata
37
     */
38
    protected function setMediaMetadata()
39
    {
40
        $mediaMetadata = $this->getDataProperty('metadata');
41
        if (is_array($mediaMetadata)) {
42
            if ($mediaMetadata['.tag'] === 'photo') {
43
                //Media is Photo
44
                $this->mediaMetadata = new PhotoMetadata($mediaMetadata);
45
            } elseif ($mediaMetadata['.tag'] === 'video') {
46
                //Media is Video
47
                $this->mediaMetadata = new VideoMetadata($mediaMetadata);
48
            } else {
49
                //Unknown Media (Quite unlikely, though.)
50
                $this->mediaMetadata = new MediaMetadata($mediaMetadata);
51
            }
52
        }
53
    }
54
55
    /**
56
     * Indicates whether the photo/video is still under
57
     * processing and is the metadata available yet.
58
     *
59
     * @return bool
60
     */
61
    public function isPending()
62
    {
63
        return $this->pending;
64
    }
65
66
    /**
67
     * The metadata for the photo/video.
68
     *
69
     * @return \Dropbox\Models\MediaMetadata
70
     */
71
    public function getMediaMetadata()
72
    {
73
        return $this->mediaMetadata;
74
    }
75
}
76