Passed
Push — main ( 0c2f80...877d81 )
by Peter
02:47
created

Command::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace QB\Generic\Statement;
6
7
use QB\Generic\IQueryPart;
8
9
class Command implements IQueryPart
10
{
11
    protected string $sql;
12
13
    /** @var IQueryPart[] */
14
    protected array $queryParts;
15
16
    /**
17
     * Command constructor.
18
     *
19
     * @param string     $sql
20
     * @param IQueryPart ...$expressions
21
     */
22 2
    public function __construct(string $sql, IQueryPart ...$expressions)
23
    {
24 2
        $this->sql        = $sql;
25 2
        $this->queryParts = $expressions;
26 2
    }
27
28
    /**
29
     * @return string
30
     */
31 2
    public function __toString(): string
32
    {
33 2
        $parts = [];
34 2
        foreach ($this->queryParts as $expr) {
35 1
            $parts[] = (string)$expr;
36
        }
37
38 2
        return sprintf($this->sql, ...$parts);
39
    }
40
41
    /**
42
     * @return array
43
     */
44 1
    public function getParams(): array
45
    {
46 1
        $params = [];
47
48 1
        foreach ($this->queryParts as $expr) {
49 1
            $params = array_merge($params, $expr->getParams());
50
        }
51
52 1
        return $params;
53
    }
54
}
55