Completed
Push — id3-metadata-objects ( 384c4c...c855dc )
by Daniel
02:54
created

HeaderMetadata   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 17.11 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 13
loc 76
ccs 0
cts 25
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
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\Filter\SynchsafeIntegerFilter;
11
use GravityMedia\Metadata\ID3v2\Flag\HeaderFlag;
12
use GravityMedia\Metadata\ID3v2\Version;
13
use GravityMedia\Stream\Stream;
14
15
/**
16
 * ID3v2 header metadata class.
17
 *
18
 * @package GravityMedia\Metadata\ID3v2\Metadata
19
 */
20
class HeaderMetadata
21
{
22
    /**
23
     * @var Stream
24
     */
25
    protected $stream;
26
27
    /**
28
     * @var int
29
     */
30
    protected $version;
31
32
    /**
33
     * @var SynchsafeIntegerFilter
34
     */
35
    protected $synchsafeIntegerFilter;
36
37
    /**
38
     * Create ID3v2 header metadata object.
39
     *
40
     * @param Stream $stream
41
     * @param int    $version
42
     */
43
    public function __construct(Stream $stream, $version)
44
    {
45
        $this->stream = $stream;
46
        $this->version = $version;
47
        $this->synchsafeIntegerFilter = new SynchsafeIntegerFilter();
48
    }
49
50
    /**
51
     * Read ID3v2 header size.
52
     *
53
     * @return int
54
     */
55
    public function readSize()
56
    {
57
        $this->stream->seek(6);
58
59
        return $this->synchsafeIntegerFilter->decode($this->stream->readUInt32());
60
    }
61
62
    /**
63
     * Read ID3v2 header flags.
64
     *
65
     * @return array
66
     */
67
    public function readFlags()
68
    {
69
        $this->stream->seek(5);
70
71
        $flags = $this->stream->readUInt8();
72
73 View Code Duplication
        if (Version::VERSION_22 === $this->version) {
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...
74
            return [
75
                HeaderFlag::FLAG_UNSYNCHRONISATION => (bool)($flags & 0x80),
76
                HeaderFlag::FLAG_COMPRESSION => (bool)($flags & 0x40)
77
            ];
78
        }
79
80 View Code Duplication
        if (Version::VERSION_23 === $this->version) {
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...
81
            return [
82
                HeaderFlag::FLAG_UNSYNCHRONISATION => (bool)($flags & 0x80),
83
                HeaderFlag::FLAG_EXTENDED_HEADER => (bool)($flags & 0x40),
84
                HeaderFlag::FLAG_EXPERIMENTAL_INDICATOR => (bool)($flags & 0x20)
85
            ];
86
        }
87
88
        return [
89
            HeaderFlag::FLAG_UNSYNCHRONISATION => (bool)($flags & 0x80),
90
            HeaderFlag::FLAG_EXTENDED_HEADER => (bool)($flags & 0x40),
91
            HeaderFlag::FLAG_EXPERIMENTAL_INDICATOR => (bool)($flags & 0x20),
92
            HeaderFlag::FLAG_FOOTER_PRESENT => (bool)($flags & 0x10)
93
        ];
94
    }
95
}
96