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

HeaderReader::readRevision()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
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\Reader;
9
10
use GravityMedia\Metadata\ID3v2\Flag\HeaderFlag;
11
use GravityMedia\Metadata\ID3v2\Version;
12
13
/**
14
 * ID3v2 header reader class.
15
 *
16
 * @package GravityMedia\Metadata\ID3v2\Reader
17
 */
18
class HeaderReader extends AbstractReader
19
{
20
    /**
21
     * @var int
22
     */
23
    private $revision;
24
25
    /**
26
     * Read ID3v2 revision.
27
     *
28
     * @return int
29
     */
30
    protected function readRevision()
31
    {
32
        $this->getStream()->seek($this->getOffset());
33
34
        return $this->getStream()->readUInt8();
35
    }
36
37
    /**
38
     * Get $revision
39
     *
40
     * @return int
41
     */
42
    public function getRevision()
43
    {
44
        if (null === $this->revision) {
45
            $this->revision = $this->readRevision();
46
        }
47
48
        return $this->revision;
49
    }
50
51
    /**
52
     * Read ID3v2 header flags.
53
     *
54
     * @return bool[]
55
     */
56
    protected function readFlags()
57
    {
58
        $this->getStream()->seek($this->getOffset() + 1);
59
60
        $flags = $this->getStream()->readUInt8();
61
62 View Code Duplication
        if (Version::VERSION_22 === $this->getVersion()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
63
            return [
64
                HeaderFlag::FLAG_UNSYNCHRONISATION => (bool)($flags & 0x80),
65
                HeaderFlag::FLAG_COMPRESSION => (bool)($flags & 0x40)
66
            ];
67
        }
68
69 View Code Duplication
        if (Version::VERSION_23 === $this->getVersion()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
70
            return [
71
                HeaderFlag::FLAG_UNSYNCHRONISATION => (bool)($flags & 0x80),
72
                HeaderFlag::FLAG_EXTENDED_HEADER => (bool)($flags & 0x40),
73
                HeaderFlag::FLAG_EXPERIMENTAL_INDICATOR => (bool)($flags & 0x20)
74
            ];
75
        }
76
77
        return [
78
            HeaderFlag::FLAG_UNSYNCHRONISATION => (bool)($flags & 0x80),
79
            HeaderFlag::FLAG_EXTENDED_HEADER => (bool)($flags & 0x40),
80
            HeaderFlag::FLAG_EXPERIMENTAL_INDICATOR => (bool)($flags & 0x20),
81
            HeaderFlag::FLAG_FOOTER_PRESENT => (bool)($flags & 0x10)
82
        ];
83
    }
84
85
    /**
86
     * Read ID3v2 header size.
87
     *
88
     * @return int
89
     */
90
    protected function readSize()
91
    {
92
        $this->getStream()->seek($this->getOffset() + 2);
93
94
        return $this->getSynchsafeIntegerFilter()->decode($this->getStream()->readUInt32());
95
    }
96
}
97