Completed
Branch 2.0 (acba87)
by Vermeulen
02:20
created

Join   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 4 1
A getOn() 0 3 1
A generate() 0 10 2
1
<?php
2
3
namespace BfwSql\Queries\Parts;
4
5
class Join extends Table
6
{
7
    /**
8
     * @var string $on The on condition used for a join
9
     */
10
    protected $on = '';
11
    
12
    /**
13
     * Getter accessor to property on
14
     * 
15
     * @return string
16
     */
17
    public function getOn(): string
18
    {
19
        return $this->on;
20
    }
21
    
22
    /**
23
     * Magic method __invoke, used when the user call object like a function
24
     * @link http://php.net/manual/en/language.oop5.magic.php#object.invoke
25
     * 
26
     * @param string|array $nameInfos The name (and shortcut) of the table
27
     * @param string|array|null $columns Columns of this table to use
28
     *  into the request
29
     * @param string $on The ON condition used by the join
30
     * 
31
     * @return void
32
     */
33
    public function __invoke($nameInfos, $columns = null, string $on = '')
34
    {
35
        parent::__invoke($nameInfos, $columns);
36
        $this->on = $on;
37
    }
38
    
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function generate(): string
43
    {
44
        $partQuery = '`'.$this->name.'`';
45
        if ($this->shortcut !== null) {
46
            $partQuery .= ' AS `'.$this->shortcut.'`';
47
        }
48
        
49
        $partQuery .= ' ON '.$this->on;
50
        
51
        return $partQuery;
52
    }
53
}
54