ColumnTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A column() 0 17 4
A buildColumnQueryPart() 0 3 2
1
<?php declare(strict_types=1);
2
3
namespace Janisbiz\LightOrm\Dms\MySQL\QueryBuilder\Traits;
4
5
use Janisbiz\LightOrm\Dms\MySQL\QueryBuilder\QueryBuilderException;
6
7
trait ColumnTrait
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $column = [];
13
14
    /**
15
     * @param array|string $column
16
     * @param boolean $clearAll
17
     *
18
     * @return $this
19
     * @throws QueryBuilderException
20
     */
21
    public function column($column, bool $clearAll = false)
22
    {
23
        if (empty($column)) {
24
            throw new QueryBuilderException('You must pass $column to column method!');
25
        }
26
27
        if (!\is_array($column)) {
28
            $column = [$column];
29
        }
30
31
        if ($clearAll == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
32
            $this->column = $column;
33
        } else {
34
            $this->column = \array_merge($this->column, $column);
35
        }
36
37
        return $this;
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    protected function buildColumnQueryPart(): string
44
    {
45
        return empty($this->column) ? '*' : \implode(', ', $this->column);
46
    }
47
}
48