Endian   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 27
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A convert() 0 13 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