Completed
Push — id3-metadata-objects ( 33018f...0cc3db )
by Daniel
07:46
created

TextFrameReader   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 17.14 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 7
c 3
b 0
f 2
lcom 1
cbo 2
dl 12
loc 70
ccs 0
cts 20
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A readEncoding() 0 6 1
A getEncoding() 0 8 2
A readText() 12 12 2
A getText() 0 8 2

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 project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Metadata\ID3v2\Reader;
9
10
use GravityMedia\Metadata\ID3v2\StreamContainer;
11
12
/**
13
 * ID3v2 text frame reader class.
14
 *
15
 * @package GravityMedia\Metadata\ID3v2\Reader
16
 */
17
class TextFrameReader extends StreamContainer
18
{
19
    /**
20
     * @var int
21
     */
22
    private $encoding;
23
24
    /**
25
     * @var string
26
     */
27
    private $text;
28
29
    /**
30
     * Read encoding.
31
     *
32
     * @return int
33
     */
34
    protected function readEncoding()
35
    {
36
        $this->getStream()->seek($this->getOffset());
37
38
        return $this->getStream()->readUInt8();
39
    }
40
41
    /**
42
     * Get encoding.
43
     *
44
     * @return int
45
     */
46
    public function getEncoding()
47
    {
48
        if (null === $this->encoding) {
49
            $this->encoding = $this->readEncoding();
50
        }
51
52
        return $this->encoding;
53
    }
54
55
    /**
56
     * Read text.
57
     *
58
     * @return string
59
     */
60 View Code Duplication
    protected function readText()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
61
    {
62
        $offset = 1;
63
        $length = $this->getStream()->getSize() - $offset;
64
        if ($length < 1) {
65
            return '';
66
        }
67
68
        $this->getStream()->seek($this->getOffset() + $offset);
69
70
        return $this->getStream()->read($length);
71
    }
72
73
    /**
74
     * Get text.
75
     *
76
     * @return string
77
     */
78
    public function getText()
79
    {
80
        if (null === $this->text) {
81
            $this->text = $this->readText();
82
        }
83
84
        return $this->text;
85
    }
86
}
87