Passed
Pull Request — master (#37)
by Eugene
03:09
created

Execute   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 10
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getBody() 0 7 2
A getType() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Tarantool Client package.
7
 *
8
 * (c) Eugene Leonovich <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Tarantool\Client\Request;
15
16
use Tarantool\Client\IProto;
17
use Tarantool\Client\RequestTypes;
18
19
final class Execute implements Request
20
{
21
    private $sql;
22
    private $params;
23
24 18
    public function __construct(string $sql, array $params = [])
25
    {
26 18
        $this->sql = $sql;
27 18
        $this->params = $params;
28 18
    }
29
30 18
    public function getType() : int
31
    {
32 18
        return RequestTypes::EXECUTE;
33
    }
34
35 18
    public function getBody() : array
36
    {
37 18
        return [] === $this->params ? [
38 14
            IProto::SQL_TEXT => $this->sql,
39
        ] : [
40 4
            IProto::SQL_TEXT => $this->sql,
41 18
            IProto::SQL_BIND => $this->params,
42
        ];
43
    }
44
}
45