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\Metadata; |
9
|
|
|
|
10
|
|
|
use GravityMedia\Metadata\ID3v2\Flag\HeaderFlag; |
11
|
|
|
use GravityMedia\Metadata\ID3v2\Version; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* ID3v2 header handler class. |
15
|
|
|
* |
16
|
|
|
* @package GravityMedia\Metadata\ID3v2\Metadata |
17
|
|
|
*/ |
18
|
|
|
class HeaderHandler extends AbstractHandler |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Read ID3v2 header size. |
22
|
|
|
* |
23
|
|
|
* @return int |
24
|
|
|
*/ |
25
|
|
|
protected function readSize() |
26
|
|
|
{ |
27
|
|
|
$this->getStream()->seek($this->getOffset() + 1); |
28
|
|
|
|
29
|
|
|
return $this->getSynchsafeIntegerFilter()->decode($this->getStream()->readUInt32()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Read ID3v2 header flags. |
34
|
|
|
* |
35
|
|
|
* @return bool[] |
36
|
|
|
*/ |
37
|
|
|
protected function readFlags() |
38
|
|
|
{ |
39
|
|
|
$this->getStream()->seek($this->getOffset()); |
40
|
|
|
|
41
|
|
|
$flags = $this->getStream()->readUInt8(); |
42
|
|
|
|
43
|
|
View Code Duplication |
if (Version::VERSION_22 === $this->getVersion()) { |
|
|
|
|
44
|
|
|
return [ |
45
|
|
|
HeaderFlag::FLAG_UNSYNCHRONISATION => (bool)($flags & 0x80), |
46
|
|
|
HeaderFlag::FLAG_COMPRESSION => (bool)($flags & 0x40) |
47
|
|
|
]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
if (Version::VERSION_23 === $this->getVersion()) { |
|
|
|
|
51
|
|
|
return [ |
52
|
|
|
HeaderFlag::FLAG_UNSYNCHRONISATION => (bool)($flags & 0x80), |
53
|
|
|
HeaderFlag::FLAG_EXTENDED_HEADER => (bool)($flags & 0x40), |
54
|
|
|
HeaderFlag::FLAG_EXPERIMENTAL_INDICATOR => (bool)($flags & 0x20) |
55
|
|
|
]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return [ |
59
|
|
|
HeaderFlag::FLAG_UNSYNCHRONISATION => (bool)($flags & 0x80), |
60
|
|
|
HeaderFlag::FLAG_EXTENDED_HEADER => (bool)($flags & 0x40), |
61
|
|
|
HeaderFlag::FLAG_EXPERIMENTAL_INDICATOR => (bool)($flags & 0x20), |
62
|
|
|
HeaderFlag::FLAG_FOOTER_PRESENT => (bool)($flags & 0x10) |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.