Passed
Push — master ( 197b26...f1b1fc )
by Eugene
03:15
created

PacketLength::unpack()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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