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

SubQueryList::generate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
c 0
b 0
f 0
rs 9.7998
cc 3
nc 3
nop 0
1
<?php
2
3
namespace BfwSql\Queries\Parts;
4
5 View Code Duplication
class SubQueryList extends AbstractList
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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