SubQueryList::generate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 0
dl 0
loc 17
rs 9.9666
c 0
b 0
f 0
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->invokeCheckIsDisabled();
24
        
25
        $usedClass   = \BfwSql\UsedClass::getInstance();
26
        $subQueryClass = $usedClass->obtainClassNameToUse('QueriesPartsSubQuery');
27
        
28
        $this->list[] = new $subQueryClass($this->querySystem, $shortcut, $subQuery);
29
    }
30
    
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function generate(): string
35
    {
36
        if ($this->isDisabled === true) {
37
            return '';
38
        }
39
        
40
        $sqlPart = '';
41
        
42
        foreach ($this->list as $index => $subQuery) {
43
            $sqlPart .= $this->querySystem->getQuerySgbd()->listItem(
44
                $subQuery->generate(),
45
                $index,
46
                $this->separator
47
            );
48
        }
49
        
50
        return $sqlPart;
51
    }
52
}
53