ColumnValueList::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BfwSql\Queries\Parts;
4
5
class ColumnValueList extends ColumnList
6
{
7
    /**
8
     * {@inheritdoc}
9
     * 
10
     * @param array $columns The list of columns to declare
11
     *  The key into the array is the name of the column.
12
     *  The value is the column value.
13
     */
14
    public function __invoke(array $columns)
15
    {
16
        $this->invokeCheckIsDisabled();
17
        
18
        $usedClass   = \BfwSql\UsedClass::getInstance();
19
        $columnClass = $usedClass->obtainClassNameToUse('QueriesPartsColumn');
20
        
21
        foreach ($columns as $name => $value) {
22
            $this->list[] = new $columnClass($this->table, $name, null, $value);
23
        }
24
    }
25
    
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function generate(): string
30
    {
31
        if ($this->isDisabled === true) {
32
            return '';
33
        }
34
        
35
        $sqlPart = '';
36
        
37
        foreach ($this->list as $index => $column) {
38
            $expr     = $column->obtainName().'='.$column->obtainValue();
39
            $sqlPart .= $this->querySystem->getQuerySgbd()->listItem(
40
                $expr,
41
                $index,
42
                $this->separator
43
            );
44
        }
45
        
46
        return $sqlPart;
47
    }
48
}
49