From   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 96%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 50
ccs 24
cts 25
cp 0.96
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A table() 0 4 1
A join() 0 19 5
A build() 0 13 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Sql\Component;
5
6
use Sirius\Sql\Bindings;
7
8
class From extends Component
9
{
10
    protected $bindings;
11
12
    protected $list = [];
13
14 17
    public function __construct(Bindings $bindings)
15
    {
16 17
        $this->bindings = $bindings;
17 17
    }
18
19 17
    public function table(string $ref): void
20
    {
21 17
        $this->list[] = [$ref];
22 17
    }
23
24 2
    public function join(string $join, string $ref, string $condition = '', ...$bindingsInline): void
25
    {
26 2
        $condition = ltrim($condition);
27
28 2
        if ($condition !== ''
29 2
            && strtoupper(substr($condition, 0, 3)) !== 'ON '
30 2
            && strtoupper(substr($condition, 0, 6)) !== 'USING '
31
        ) {
32 2
            $condition = 'ON ' . $condition;
33
        }
34
35 2
        if (! empty($bindingsInline)) {
36 1
            $condition = $this->bindings->sprintf($condition, ...$bindingsInline);
37
        }
38
39 2
        end($this->list);
40 2
        $end                = key($this->list);
41 2
        $this->list[$end][] = "    {$join} {$ref} {$condition}";
42 2
    }
43
44 16
    public function build(): string
45
    {
46 16
        if (empty($this->list)) {
47
            return '';
48
        }
49
50 16
        $from = [];
51 16
        foreach ($this->list as $list) {
52 16
            $from[] = array_shift($list) . $this->indent($list);
53
        }
54
55 16
        return PHP_EOL . 'FROM' . $this->indentCsv($from);
56
    }
57
}
58