Passed
Push — master ( 197b26...f1b1fc )
by Eugene
03:15
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
use Tarantool\Client\Exception\UnpackingFailed;
17
18
final class PacketLength
19
{
20
    public const SIZE_BYTES = 5;
21
22
    private function __construct()
23
    {
24
    }
25
26 194
    public static function pack(int $length) : string
27
    {
28 194
        return \pack('CN', 0xce, $length);
29
    }
30
31 190
    public static function unpack(string $data) : int
32
    {
33 190
        if (false === $data = @\unpack('C/N', $data)) {
34 2
            throw new UnpackingFailed('Unable to unpack length value.');
35
        }
36
37 188
        return $data[1];
38
    }
39
}
40