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

SubQueryList   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 13 3
A __invoke() 0 3 1
1
<?php
2
3
namespace BfwSql\Queries\Parts;
4
5
class SubQueryList extends AbstractList
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10
    protected $separator = ',';
11
    
12
    /**
13
     * Magic method __invoke, used when the user call object like a function
14
     * @link http://php.net/manual/en/language.oop5.magic.php#object.invoke
15
     * 
16
     * @param string $shortcut The shortcut to use into the request
17
     * @param string|\BfwSql\Queries\AbstractQuery $subQuery The sub-query
18
     * 
19
     * @return void
20
     */
21
    public function __invoke(string $shortcut, $subQuery)
22
    {
23
        $this->list[] = new SubQuery($shortcut, $subQuery);
24
    }
25
    
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function generate(): string
30
    {
31
        $sqlPart = '';
32
        
33
        foreach ($this->list as $index => $subQuery) {
34
            if ($index > 0) {
35
                $sqlPart .= $this->separator;
36
            }
37
            
38
            $sqlPart .= $subQuery->generate();
39
        }
40
        
41
        return $sqlPart;
42
    }
43
}
44