Completed
Pull Request — master (#72)
by Thibaud
08:29
created

Subdef::getPlayerType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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 PhraseanetSDK\Annotation\ApiField as ApiField;
15
use PhraseanetSDK\Annotation\ApiRelation as ApiRelation;
16
use PhraseanetSDK\Annotation\Id as Id;
17
18
class Subdef
19
{
20
21 7
    public static function fromList(array $values)
22
    {
23 7
        $subdefs = array();
24
25 7
        foreach ($values as $value) {
26 7
            if ($value == null) {
27
                continue;
28
            }
29
30 7
            $subdefs[$value->name] = self::fromValue($value);
31 7
        }
32
33 7
        return $subdefs;
34
    }
35
36 14
    public static function fromValue(\stdClass $value)
37
    {
38 14
        return new self($value);
39
    }
40
41
    /**
42
     * @var \stdClass
43
     */
44
    protected $source;
45
46
    /**
47
     * @var Permalink
48
     */
49
    protected $permalink;
50
51
    /**
52
     * @param \stdClass $source
53
     */
54 14
    public function __construct(\stdClass $source)
55
    {
56 14
        $this->source = $source;
57 14
    }
58
59
    /**
60
     * @return \stdClass
61
     */
62
    public function getRawData()
63
    {
64
        return $this->source;
65
    }
66
67
    /**
68
     * @return \stdClass
69
     * @deprecated Use getRawData() instead
70
     */
71
    public function getSource()
72 14
    {
73
        return $this->source;
74 14
    }
75
76
    /**
77
     * Get subdef name
78
     *
79
     * @return string
80
     */
81
    public function getName()
82 13
    {
83
        return $this->source->name;
84 13
    }
85
86
    /**
87
     * Get subdef height
88
     *
89
     * @return integer
90
     */
91
    public function getHeight()
92 13
    {
93
        return $this->source->height;
94 13
    }
95
96
    /**
97
     * Get subdef width
98
     *
99
     * @return integer
100
     */
101
    public function getWidth()
102 13
    {
103
        return $this->source->width;
104 13
    }
105
106
    /**
107
     * Get subdef file size
108
     *
109
     * @return integer
110
     */
111
    public function getFileSize()
112 13
    {
113
        return $this->source->filesize;
114 13
    }
115
116
    /**
117
     * Get the player type
118
     *
119
     * @return string
120
     */
121
    public function getPlayerType()
122 13
    {
123
        return $this->source->player_type;
124 13
    }
125
126
    /**
127
     * Get subdef mime type
128
     *
129
     * @return string
130
     */
131
    public function getMimeType()
132 13
    {
133
        return $this->source->mime_type;
134 13
    }
135
136
    /**
137
     * Get the permalink related to the subdef
138
     *
139
     * @return Permalink
140
     */
141
    public function getPermalink()
142
    {
143
        return $this->permalink ?: $this->permalink = Permalink::fromValue($this->source->permalink);
144
    }
145
}
146