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

Command::getParams()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
ccs 5
cts 5
cp 1
crap 2
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