Completed
Push — master ( bd49b2...323004 )
by
unknown
18s 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
namespace Spiral\Goridge;
10
11
if (!function_exists('packMessage')) {
12
    /**
13
     * @param string   $payload
14
     * @param int|null $flags
15
     * @return array|null
16
     * @internal
17
     */
18
    function packMessage(string $payload, ?int $flags = null): ?array
19
    {
20
        $size = strlen($payload);
21
        if ($flags & RelayInterface::PAYLOAD_NONE && $size !== 0) {
22
            return null;
23
        }
24
25
        $body = pack('CPJ', $flags, $size, $size);
26
27
        if (!($flags & RelayInterface::PAYLOAD_NONE)) {
28
            $body .= $payload;
29
        }
30
31
        return compact('body', 'size');
32
    }
33
}
34