Passed
Push — master ( 1f87bb...62bbca )
by Eugene
03:04
created

PacketLength   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 4
eloc 6
dl 0
loc 20
ccs 6
cts 8
cp 0.75
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A unpack() 0 7 2
A pack() 0 3 1
A __construct() 0 2 1
1
<?php
2
3
/**
4
 * This file is part of the Tarantool Client package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Tarantool\Client\Packer;
15
16
final class PacketLength
17
{
18
    public const SIZE_BYTES = 5;
19
20
    private function __construct()
21
    {
22
    }
23
24 232
    public static function pack(int $length) : string
25
    {
26 232
        return \pack('CN', 0xce, $length);
27
    }
28
29 198
    public static function unpack(string $data) : int
30
    {
31 198
        if (false === $data = @\unpack('C/N', $data)) {
32 2
            throw new \RuntimeException('Unable to unpack packet length.');
33
        }
34
35 196
        return $data[1];
36
    }
37
}
38