PreparedStatement::getMetadata()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
/**
4
 * This file is part of the tarantool/client package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Tarantool\Client;
15
16
use Tarantool\Client\Handler\Handler;
17
use Tarantool\Client\Request\ExecuteRequest;
18
use Tarantool\Client\Request\PrepareRequest;
19
20
final class PreparedStatement
21
{
22
    private $handler;
23
    private $id;
24
    private $bindCount;
25
    private $bindMetadata;
26
    private $metadata;
27
28 28
    public function __construct(Handler $handler, int $id, int $bindCount, array $bindMetadata, array $metadata)
29
    {
30 28
        $this->handler = $handler;
31 28
        $this->id = $id;
32 28
        $this->bindCount = $bindCount;
33 28
        $this->bindMetadata = $bindMetadata;
34 28
        $this->metadata = $metadata;
35
    }
36
37
    /**
38
     * @param mixed ...$params
39
     */
40 4
    public function execute(...$params) : Response
41
    {
42 4
        return $this->handler->handle(
43 4
            ExecuteRequest::fromStatementId($this->id, $params)
44 4
        );
45
    }
46
47
    /**
48
     * @param mixed ...$params
49
     */
50 8
    public function executeQuery(...$params) : SqlQueryResult
51
    {
52 8
        $response = $this->handler->handle(
53 8
            ExecuteRequest::fromStatementId($this->id, $params)
54 8
        );
55
56 8
        return new SqlQueryResult(
57 8
            $response->getBodyField(Keys::DATA),
58 8
            $response->getBodyField(Keys::METADATA)
59 8
        );
60
    }
61
62
    /**
63
     * @param mixed ...$params
64
     */
65 4
    public function executeUpdate(...$params) : SqlUpdateResult
66
    {
67 4
        $response = $this->handler->handle(
68 4
            ExecuteRequest::fromStatementId($this->id, $params)
69 4
        );
70
71 4
        return new SqlUpdateResult($response->getBodyField(Keys::SQL_INFO));
72
    }
73
74 24
    public function close() : void
75
    {
76 24
        $this->handler->handle(PrepareRequest::fromStatementId($this->id));
77
    }
78
79 4
    public function getId() : int
80
    {
81 4
        return $this->id;
82
    }
83
84 4
    public function getBindCount() : int
85
    {
86 4
        return $this->bindCount;
87
    }
88
89 4
    public function getBindMetadata() : array
90
    {
91 4
        return $this->bindMetadata;
92
    }
93
94 4
    public function getMetadata() : array
95
    {
96 4
        return $this->metadata;
97
    }
98
}
99