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

SynchsafeIntegerFilter::decode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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