Endian::convert()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
3
namespace PhpBinaryReader;
4
5
class Endian
6
{
7
    const ENDIAN_BIG = 1;
8
    const ENDIAN_LITTLE = 2;
9
    const BIG = 1;
10
    const LITTLE = 2;
11
12
    /**
13
     * Converts the endianess of a number from big to little or vise-versa
14
     *
15
     * @param  int $value
16
     * @return int
17
     */
18 6
    public function convert($value)
19
    {
20 6
        $data = dechex($value);
21
22 6
        if (strlen($data) <= 2) {
23 5
            return $value;
24
        }
25
26 1
        $unpack = unpack("H*", strrev(pack("H*", $data)));
27 1
        $converted = hexdec($unpack[1]);
28
29 1
        return $converted;
30
    }
31
}
32