StorageRequest::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 5
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace seregazhuk\React\Memcached\Protocol\Request;
4
5
use seregazhuk\React\Memcached\Protocol\Parser;
6
7
final class StorageRequest extends Request
8
{
9
    /**
10
     * @param string $command
11
     * @param string $key
12
     * @param mixed $value
13
     * @param int $flags
14
     * @param int $expiration
15
     */
16
    public function __construct($command, $key, $value, $flags = 0, $expiration = 0)
17
    {
18
        // Serialize non-numeric values. Numeric values should stay as they are
19
        // because they could be incremented/decremented.
20
        $value = is_numeric($value) ? $value : serialize($value);
21
        
22
        $command = implode(' ', [$command, $key, $flags, $expiration, strlen($value)]);
23
24
        $this->command = $command . Parser::COMMAND_SEPARATOR . $value . Parser::COMMAND_SEPARATOR;
25
    }
26
}
27