Completed
Push — master ( dea784...77743f )
by
unknown
21s queued 11s
created

functions.php ➔ packMessage()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 2
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Dead simple, high performance, drop-in bridge to Golang RPC with zero dependencies
5
 *
6
 * @author Valentin V
7
 */
8
9
declare(strict_types=1);
10
11
namespace Spiral\Goridge;
12
13
if (!function_exists('packMessage')) {
14
    /**
15
     * @param string   $payload
16
     * @param int|null $flags
17
     * @return array|null
18
     * @internal
19
     */
20
    function packMessage(string $payload, ?int $flags = null): ?array
21
    {
22
        $size = strlen($payload);
23
        if ($flags & RelayInterface::PAYLOAD_NONE && $size !== 0) {
24
            return null;
25
        }
26
27
        $body = pack('CPJ', $flags, $size, $size);
28
29
        if (!($flags & RelayInterface::PAYLOAD_NONE)) {
30
            $body .= $payload;
31
        }
32
33
        return compact('body', 'size');
34
    }
35
}
36