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

SynchsafeIntegerFilter   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\Filter;
9
10
/**
11
 * Synchsafe integer filter class.
12
 *
13
 * @package GravityMedia\Metadata\ID3v2\Filter
14
 */
15
class SynchsafeIntegerFilter
16
{
17
    /**
18
     * Encode value.
19
     *
20
     * @param int $value
21
     *
22
     * @return int
23
     */
24
    public function encode($value)
25
    {
26
        return ($value & 0x7f) | ($value & 0x3f80) << 1 | ($value & 0x1fc000) << 2 | ($value & 0xfe00000) << 3;
27
    }
28
29
    /**
30
     * Decode value.
31
     *
32
     * @param int $value
33
     *
34
     * @return int
35
     */
36
    public function decode($value)
37
    {
38
        return ($value & 0x7f) | ($value & 0x7f00) >> 1 | ($value & 0x7f0000) >> 2 | ($value & 0x7f000000) >> 3;
39
    }
40
}
41