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

Command   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 44
rs 10
ccs 14
cts 14
cp 1
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 8 2
A __construct() 0 4 1
A getParams() 0 9 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