Completed
Push — master ( 229d8c...e7f8de )
by Dmitry
02:48
created

Event::getResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Tarantool\Mapper;
4
5
use Tarantool\Client\Connection\Connection;
6
use Tarantool\Client\IProto;
7
use Tarantool\Client\Request\EvaluateRequest;
8
use Tarantool\Client\Request\Request;
9
use Tarantool\Client\Request\SelectRequest;
10
11
class Event
12
{
13
    private $time;
14
    private $class;
15
    private $request;
16
    private $response;
17
18 64
    public function __construct($time, $class, $request, $response)
19
    {
20 64
        $this->time = $time;
21 64
        $this->class = $class;
22 64
        $this->request = $request;
23 64
        $this->response = $response;
24 64
    }
25
26
    public function render(Manager $manager)
27
    {
28
        switch ($this->class) {
29
            case Connection::class:
30
                return 'Make connection';
31
32
            case EvaluateRequest::class:
33
                return trim($this->request[39]);
34
35
            case SelectRequest::class:
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
36
37
                $params = $this->request[IProto::KEY];
38
                $spaceId = $this->request[IProto::SPACE_ID];
39
                $index = $this->request[IProto::INDEX_ID];
40
41
                $client = $manager->getClient();
42
                $meta = $manager->getMeta();
43
                $schema = $manager->getSchema();
44
                $space = $schema->getSpaceName($spaceId);
45
46
                if ($meta->has($space)) {
47
                    $index = $meta->get($space)->getIndex($index);
48
                } else {
49
                    $data = $client->getSpace('_vindex')->select([$this->request[IProto::SPACE_ID], $index], 'primary')->getData();
50
                    $index = [];
51
52
                    foreach ($data[0][5] as $row) {
53
                        $index[] = $row[0];
54
                    }
55
                }
56
57
                if (count($params) == 1) {
58
                    $params = array_shift($params);
59
                    $index = array_shift($index);
60
                } else {
61
                    $params = json_encode($params);
62
                    $index = json_encode($index);
63
                }
64
65
                return "select $space where $index = $params";
66
            default:
67
                return json_encode($this->request);
68
        }
69
    }
70
71
    public function getTime()
72
    {
73
        return $this->time;
74
    }
75
76
    public function getResponse()
77
    {
78
        return $this->response;
79
    }
80
}
81