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

Filter::encode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * This file is part of the ID3 project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Metadata\ID3v1;
9
10
/**
11
 * ID3v1 filter class.
12
 *
13
 * @package GravityMedia\Metadata\ID3v1
14
 */
15
class Filter
16
{
17
    /**
18
     * Encode data.
19
     *
20
     * @param string $data   The data to encode.
21
     * @param int    $length The final length.
22
     *
23
     * @return string
24
     */
25 4
    public function encode($data, $length)
26
    {
27 4
        return str_pad(substr($data, 0, $length), $length, "\x00", STR_PAD_RIGHT);
28
    }
29
30
    /**
31
     * Decode data.
32
     *
33
     * @param string $data The data to decode.
34
     *
35
     * @return string
36
     */
37 6
    public function decode($data)
38
    {
39 6
        return rtrim($data, "\x00");
40
    }
41
}
42