Completed
Push — id3-metadata-objects ( 3a53b8...e55453 )
by Daniel
14:15
created

Unsynchronisation::decode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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\Converter;
9
10
/**
11
 * Unsynchronisation converter
12
 *
13
 * @package GravityMedia\Metadata\ID3v2
14
 */
15
class Unsynchronisation
16
{
17
    /**
18
     * Encode unsynchronisation.
19
     *
20
     * @param string $data
21
     *
22
     * @return string
23
     */
24
    public static function encode($data)
25
    {
26
        return preg_replace('/\xff(?=[\xe0-\xff])/', "\xff\x00", preg_replace('/\xff\x00/', "\xff\x00\x00", $data));
27
    }
28
29
    /**
30
     * Decode unsynchronisation.
31
     *
32
     * @param string $data
33
     *
34
     * @return string
35
     */
36
    public static function decode($data)
37
    {
38
        return preg_replace('/\xff\x00\x00/', "\xff\x00", preg_replace('/\xff\x00(?=[\xe0-\xff])/', "\xff", $data));
39
    }
40
}
41