Completed
Push — id3-metadata-objects ( c855dc...168cf3 )
by Daniel
03:05
created

TextInformationFrame::readInformation()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 19
ccs 0
cts 12
cp 0
rs 8.8571
cc 5
eloc 13
nc 5
nop 1
crap 30
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\Frame;
9
10
use GravityMedia\Metadata\ID3v2\Encoding;
11
use GravityMedia\Stream\Stream;
12
13
/**
14
 * ID3v2 text information frame class.
15
 *
16
 * @package GravityMedia\Metadata\ID3v2\Metadata\Frame
17
 */
18
class TextInformationFrame
19
{
20
    /**
21
     * @var Stream
22
     */
23
    protected $stream;
24
25
    /**
26
     * @var int
27
     */
28
    protected $version;
29
30
    /**
31
     * Create ID3v2 header metadata object.
32
     *
33
     * @param Stream $stream
34
     * @param int $version
35
     */
36
    public function __construct(Stream $stream, $version)
37
    {
38
        $this->stream = $stream;
39
        $this->version = $version;
40
    }
41
42
    /**
43
     * Read text encoding.
44
     *
45
     * @return int
46
     */
47
    public function readTextEncoding()
48
    {
49
        $this->stream->seek(0);
50
51
        return $this->stream->readUInt8();
52
    }
53
54
    /**
55
     * Read information.
56
     *
57
     * @param int $textEncoding
58
     *
59
     * @return string
60
     */
61
    public function readInformation($textEncoding)
62
    {
63
        $this->stream->seek(1);
64
65
        $information = $this->stream->read($this->stream->getSize() - 1);
66
67
        switch ($textEncoding) {
68
            case Encoding::ISO_8859_1:
69
                return iconv('ISO-8859-1', 'UTF-8', $information);
70
            case Encoding::UTF_16:
71
                return iconv('UTF-16', 'UTF-8', $information);
72
            case Encoding::UTF_16BE:
73
                return iconv('UTF-16BE', 'UTF-8', $information);
74
            case Encoding::UTF_16LE:
75
                return iconv('UTF-16LE', 'UTF-8', $information);
76
        }
77
78
        return $information;
79
    }
80
}
81