Completed
Push — id3-metadata-objects ( 168cf3...e37014 )
by Daniel
08:47
created

HeaderHandler::readFlags()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 28
Code Lines 17

Duplication

Lines 13
Ratio 46.43 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 13
loc 28
ccs 0
cts 17
cp 0
rs 8.8571
cc 3
eloc 17
nc 3
nop 0
crap 12
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()) {
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...
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()) {
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...
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