JoinList::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 3
dl 0
loc 12
rs 10
c 0
b 0
f 0
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
        $this->invokeCheckIsDisabled();
59
        
60
        $usedClass   = \BfwSql\UsedClass::getInstance();
61
        $joinClass = $usedClass->obtainClassNameToUse('QueriesPartsJoin');
62
        
63
        $join = new $joinClass($this->querySystem);
64
        $join->setColumnsWithValue($this->columnsWithValue);
65
        $join->__invoke($nameInfos, $columns, $on);
66
        
67
        $this->list[] = $join;
68
    }
69
    
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function generate(): string
74
    {
75
        if ($this->isDisabled === true) {
76
            return '';
77
        }
78
        
79
        $sqlPart = '';
80
        
81
        foreach ($this->list as $index => $join) {
82
            $sqlPart .= $this->querySystem->getQuerySgbd()->listItem(
83
                $this->partPrefix.' '.$join->generate(),
84
                $index,
85
                $this->separator
86
            );
87
        }
88
        
89
        return $sqlPart;
90
    }
91
}
92