Completed
Push — id3-metadata-objects ( e37014...ee91c4 )
by Daniel
12:20
created

Tag   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 189
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 12
Bugs 1 Features 2
Metric Value
wmc 14
c 12
b 1
f 2
lcom 2
cbo 2
dl 0
loc 189
ccs 0
cts 39
cp 0
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A getVersion() 0 4 1
A getRevision() 0 4 1
A setRevision() 0 6 1
A getPadding() 0 4 1
A setPadding() 0 6 1
A getCrc32() 0 4 1
A setCrc32() 0 6 1
A getRestriction() 0 8 2
A setRestrictions() 0 6 1
A getFrames() 0 4 1
A addFrame() 0 6 1
1
<?php
2
/**
3
 * This file is part of the Metadata package.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Metadata\ID3v2;
9
10
use GravityMedia\Metadata\Exception\InvalidArgumentException;
11
12
/**
13
 * ID3v2 tag class.
14
 *
15
 * @package GravityMedia\Metadata\ID3v2
16
 */
17
class Tag
18
{
19
    /**
20
     * @var int
21
     */
22
    protected $version;
23
24
    /**
25
     * @var int
26
     */
27
    protected $revision;
28
29
    /**
30
     * @var int
31
     */
32
    protected $padding;
33
34
    /**
35
     * @var int
36
     */
37
    protected $crc32;
38
39
    /**
40
     * @var int[]
41
     */
42
    protected $restrictions;
43
44
    /**
45
     * @var Frame[]
46
     */
47
    protected $frames;
48
49
    /**
50
     * Create ID3v2 tag object.
51
     *
52
     * @param int $version The version (default is 3: v2.3)
53
     *
54
     * @throws InvalidArgumentException An exception is thrown on invalid version arguments
55
     */
56
    public function __construct($version = Version::VERSION_23)
57
    {
58
        if (!in_array($version, Version::values(), true)) {
59
            throw new InvalidArgumentException('Invalid version.');
60
        }
61
62
        $this->version = $version;
63
        $this->revision = 0;
64
        $this->padding = 0;
65
        $this->crc32 = 0;
66
        $this->restrictions = [];
67
        $this->frames = [];
68
    }
69
70
    /**
71
     * Get version.
72
     *
73
     * @return int
74
     */
75
    public function getVersion()
76
    {
77
        return $this->version;
78
    }
79
80
    /**
81
     * Get revision.
82
     *
83
     * @return int
84
     */
85
    public function getRevision()
86
    {
87
        return $this->revision;
88
    }
89
90
    /**
91
     * Set revision.
92
     *
93
     * @param int $revision
94
     *
95
     * @return $this
96
     */
97
    public function setRevision($revision)
98
    {
99
        $this->revision = $revision;
100
101
        return $this;
102
    }
103
104
    /**
105
     * Get padding.
106
     *
107
     * @return int
108
     */
109
    public function getPadding()
110
    {
111
        return $this->padding;
112
    }
113
114
    /**
115
     * Set padding.
116
     *
117
     * @param int $padding
118
     *
119
     * @return $this
120
     */
121
    public function setPadding($padding)
122
    {
123
        $this->padding = $padding;
124
125
        return $this;
126
    }
127
128
    /**
129
     * Get CRC-32.
130
     *
131
     * @return int
132
     */
133
    public function getCrc32()
134
    {
135
        return $this->crc32;
136
    }
137
138
    /**
139
     * Set CRC-32.
140
     *
141
     * @param int $crc32
142
     *
143
     * @return $this
144
     */
145
    public function setCrc32($crc32)
146
    {
147
        $this->crc32 = $crc32;
148
149
        return $this;
150
    }
151
152
    /**
153
     * Get restriction.
154
     *
155
     * @param int $restriction
156
     *
157
     * @return int
158
     */
159
    public function getRestriction($restriction)
160
    {
161
        if (isset($this->restrictions[$restriction])) {
162
            return $this->restrictions[$restriction];
163
        }
164
165
        return -1;
166
    }
167
168
    /**
169
     * Set restrictions
170
     *
171
     * @param int[] $restrictions
172
     *
173
     * @return $this
174
     */
175
    public function setRestrictions(array $restrictions)
176
    {
177
        $this->restrictions = $restrictions;
178
179
        return $this;
180
    }
181
182
    /**
183
     * Get frames
184
     *
185
     * @return Frame[]
186
     */
187
    public function getFrames()
188
    {
189
        return $this->frames;
190
    }
191
192
    /**
193
     * Add frame
194
     *
195
     * @param Frame $frame
196
     *
197
     * @return $this
198
     */
199
    public function addFrame(Frame $frame)
200
    {
201
        $this->frames[] = $frame;
202
203
        return $this;
204
    }
205
}
206