Completed
Push — 2.0 ( 1160ec...acba87 )
by Vermeulen
05:15
created

JoinList   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 78
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getColumnsWithValue() 0 4 1
A setColumnsWithValue() 0 5 1
A __invoke() 0 8 1
A generate() 0 14 3
1
<?php
2
3
namespace BfwSql\Queries\Parts;
4
5
class JoinList extends AbstractList
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10
    protected $separator = "\n";
11
    
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected $usePartPrefix = false;
16
    
17
    /**
18
     * @var boolean $columnsWithValue If columns should have a value
19
     */
20
    protected $columnsWithValue = false;
21
    
22
    /**
23
     * Getter accessor to property columnsWithValue
24
     * 
25
     * @return bool
26
     */
27
    public function getColumnsWithValue(): bool
28
    {
29
        return $this->columnsWithValue;
30
    }
31
    
32
    /**
33
     * Setter accessor to property columnsWithValue
34
     * 
35
     * @param bool $columnsWithValue
36
     * 
37
     * @return $this
38
     */
39
    public function setColumnsWithValue(bool $columnsWithValue): self
40
    {
41
        $this->columnsWithValue = $columnsWithValue;
42
        return $this;
43
    }
44
    
45
    /**
46
     * Magic method __invoke, used when the user call object like a function
47
     * @link http://php.net/manual/en/language.oop5.magic.php#object.invoke
48
     * 
49
     * @param string|array $nameInfos The name (and shortcut) of the table
50
     * @param string $on The ON condition used by the join
51
     * @param string|array|null $columns Columns of this table to use
52
     *  into the request
53
     * 
54
     * @return void
55
     */
56
    public function __invoke($nameInfos, string $on, $columns = null)
57
    {
58
        $join = new Join($this->querySystem);
59
        $join->setColumnsWithValue($this->columnsWithValue);
60
        $join->__invoke($nameInfos, $columns, $on);
61
        
62
        $this->list[] = $join;
63
    }
64
    
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function generate(): string
69
    {
70
        $sqlPart = '';
71
        
72
        foreach ($this->list as $index => $join) {
73
            if ($index > 0) {
74
                $sqlPart .= $this->separator;
75
            }
76
            
77
            $sqlPart .= $this->partPrefix.' '.$join->generate();
78
        }
79
        
80
        return $sqlPart;
81
    }
82
}
83