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

TextFrameReader::getEncoding()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 8
ccs 0
cts 5
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 6
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