Passed
Pull Request — master (#62)
by Eugene
07:10
created

PacketLength::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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