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

TextInformationFrame   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 70
ccs 0
cts 14
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A readTextEncoding() 0 4 1
A readInformation() 0 15 3
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\Stream\Stream;
11
12
/**
13
 * ID3v2 text information frame class.
14
 *
15
 * @package GravityMedia\Metadata\ID3v2\Metadata\Frame
16
 */
17
class TextInformationFrame
18
{
19
    /**
20
     * The ISO-8859-1 encoding.
21
     */
22
    const ISO88591 = 0;
23
24
    /**
25
     * The UTF-16 Unicode encoding with BOM.
26
     * */
27
    const UTF16 = 1;
28
29
    /**
30
     * The UTF-16BE Unicode encoding without BOM.
31
     */
32
    const UTF16BE = 2;
33
34
    /**
35
     * The UTF-8 Unicode encoding.
36
     */
37
    const UTF8 = 3;
38
39
    /**
40
     * The UTF-16LE Unicode encoding without BOM.
41
     * */
42
    const UTF16LE = 4;
43
44
    /**
45
     * @var Stream
46
     */
47
    protected $stream;
48
49
    /**
50
     * @var int
51
     */
52
    protected $version;
53
54
    /**
55
     * Create ID3v2 header metadata object.
56
     *
57
     * @param Stream $stream
58
     * @param int    $version
59
     */
60
    public function __construct(Stream $stream, $version)
61
    {
62
        $this->stream = $stream;
63
        $this->version = $version;
64
    }
65
66
    public function readTextEncoding()
67
    {
68
        return $this->stream->readUInt8();
69
    }
70
71
    public function readInformation($textEncoding)
72
    {
73
        $this->stream->seek(1);
74
75
        $information = $this->stream->read($this->stream->getSize() - 1);
76
77
        switch ($textEncoding) {
78
            case self::ISO88591:
79
                return iconv('ISO-8859-1', 'UTF-8', $information);
80
            case self::UTF16:
81
                return iconv('UTF-16', 'UTF-8', $information);
82
        }
83
84
        return $information;
85
    }
86
}
87