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

HeaderHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 27.08 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 13
loc 48
ccs 0
cts 20
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A readSize() 0 6 1
B readFlags() 13 28 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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