MultipleGet::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Redislabs\Module\ReJSON\Command;
5
6
use Redislabs\Exceptions\InvalidNumberOfArgumentsException;
7
use Redislabs\Interfaces\CommandInterface;
8
use Redislabs\Command\CommandAbstract;
9
use Redislabs\Module\ReJSON\Path;
10
11
final class MultipleGet extends CommandAbstract implements CommandInterface
12
{
13
    protected static $command = 'JSON.MGET';
14
15
    private function __construct(array $keys, Path $path)
16
    {
17
        $this->arguments = $keys;
18
        $this->arguments[] = $path->getPath();
19
        $this->responseCallback = function ($result) {
20
            return array_map('json_decode', $result);
21
        };
22
    }
23
24
    public static function createCommandWithArguments(array $arguments) : CommandInterface
25
    {
26
        if (count($arguments) <2) {
27
            throw new InvalidNumberOfArgumentsException(
28
                sprintf('ReJSON::mget needs at least 2 arguments!, % given', count($arguments))
29
            );
30
        }
31
        $path = array_pop($arguments);
32
        $keys = $arguments;
33
        return new self(
34
            $keys,
35
            new Path($path)
36
        );
37
    }
38
}
39