MultipleGet   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 14
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createCommandWithArguments() 0 12 2
A __construct() 0 6 1
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