OrderList::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BfwSql\Queries\Parts;
4
5
class OrderList extends AbstractList
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10
    protected $partPrefix = 'ORDER BY';
11
    
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected $separator = ',';
16
    
17
    /**
18
     * Magic method __invoke, used when the user call object like a function
19
     * @link http://php.net/manual/en/language.oop5.magic.php#object.invoke
20
     * 
21
     * @param string $expr The expression to use into the order
22
     * @param string|null $sort The sort order : ASC or DESC
23
     * 
24
     * @return void
25
     */
26
    public function __invoke(string $expr, $sort = 'ASC')
27
    {
28
        $this->invokeCheckIsDisabled();
29
        
30
        $usedClass   = \BfwSql\UsedClass::getInstance();
31
        $orderClass = $usedClass->obtainClassNameToUse('QueriesPartsOrder');
32
        
33
        $this->list[] = new $orderClass($this->querySystem, $expr, $sort);
34
    }
35
    
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function generate(): string
40
    {
41
        if ($this->isDisabled === true) {
42
            return '';
43
        }
44
        
45
        $sqlPart = '';
46
        
47
        foreach ($this->list as $index => $order) {
48
            $sqlPart .= $this->querySystem->getQuerySgbd()->listItem(
49
                $order->generate(),
50
                $index,
51
                $this->separator
52
            );
53
        }
54
        
55
        return $sqlPart;
56
    }
57
}
58