Completed
Push — id3-metadata-objects ( ecc500...384c4c )
by Daniel
04:34
created

Unsynchronisation   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 26
ccs 0
cts 4
cp 0
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 Metadata package.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Metadata\ID3v2;
9
10
/**
11
 * Unsynchronisation class.
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