TableTrait::buildFromQueryPart()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Janisbiz\LightOrm\Dms\MySQL\QueryBuilder\Traits;
4
5
use Janisbiz\LightOrm\Dms\MySQL\Enum\ConditionEnum;
6
use Janisbiz\LightOrm\Dms\MySQL\QueryBuilder\QueryBuilderException;
7
8
trait TableTrait
9
{
10
    /**
11
     * @var string[]
12
     */
13
    protected $table = [];
14
15
    /**
16
     * @param string[]|string $table
17
     * @param bool $clearAll
18
     *
19
     * @return $this
20
     * @throws QueryBuilderException
21
     */
22
    public function table($table, bool $clearAll = false)
23
    {
24
        if (empty($table)) {
25
            throw new QueryBuilderException('You must pass $table to table method!');
26
        }
27
28
        if (!\is_array($table)) {
29
            $table = [$table];
30
        }
31
32
        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...
33
            $this->table = $table;
34
        } else {
35
            $this->table = \array_merge($this->table, $table);
36
        }
37
38
        return $this;
39
    }
40
41
    /**
42
     * @return null|string
43
     */
44
    protected function buildTableQueryPart(): ?string
45
    {
46
        return \reset($this->table) ?: null;
47
    }
48
49
    /**
50
     * @return null|string
51
     */
52
    protected function buildFromQueryPart(): ?string
53
    {
54
        return empty($this->table)
55
            ? null
56
            : \sprintf('%s %s', ConditionEnum::FROM, \implode(', ', $this->table))
57
        ;
58
    }
59
}
60