PackUtil   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 55
ccs 17
cts 19
cp 0.8947
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A packLongLE() 0 13 2
A unpackLongLE() 0 8 2
A toSignedInt32() 0 11 3
1
<?php
2
3
namespace PhpZip\Util;
4
5
/**
6
 * Pack util.
7
 *
8
 * @author Ne-Lexa [email protected]
9
 * @license MIT
10
 *
11
 * @internal
12
 */
13
final class PackUtil
14
{
15
    /**
16
     * @param int $longValue
17
     *
18
     * @return string
19
     */
20 9
    public static function packLongLE($longValue)
21
    {
22 9
        if (\PHP_VERSION_ID >= 506030) {
23
            return pack('P', $longValue);
24
        }
25
26 9
        $left = 0xffffffff00000000;
27 9
        $right = 0x00000000ffffffff;
28
29 9
        $r = ($longValue & $left) >> 32;
30 9
        $l = $longValue & $right;
31
32 9
        return pack('VV', $l, $r);
33
    }
34
35
    /**
36
     * @param string $value
37
     *
38
     * @return int
39
     */
40 10
    public static function unpackLongLE($value)
41
    {
42 10
        if (\PHP_VERSION_ID >= 506030) {
43
            return unpack('P', $value)[1];
44
        }
45 10
        $unpack = unpack('Va/Vb', $value);
46
47 10
        return $unpack['a'] + ($unpack['b'] << 32);
48
    }
49
50
    /**
51
     * Cast to signed int 32-bit.
52
     *
53
     * @param int $int
54
     *
55
     * @return int
56
     */
57 5
    public static function toSignedInt32($int)
58
    {
59 5
        if (\PHP_INT_SIZE === 8) {
60 5
            $int &= 0xffffffff;
61
62 5
            if ($int & 0x80000000) {
63 5
                return $int - 0x100000000;
64
            }
65
        }
66
67 5
        return $int;
68
    }
69
}
70