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

Filter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 27
ccs 4
cts 4
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A encode() 0 4 1
A decode() 0 4 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