UnionTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildUnionAllQueryPart() 0 3 2
A unionAll() 0 14 2
1
<?php declare(strict_types=1);
2
3
namespace Janisbiz\LightOrm\Dms\MySQL\QueryBuilder\Traits;
4
5
use Janisbiz\LightOrm\Dms\MySQL\Enum\CommandEnum;
6
use Janisbiz\LightOrm\Dms\MySQL\QueryBuilder\QueryBuilderException;
7
use Janisbiz\LightOrm\Dms\MySQL\QueryBuilder\QueryBuilderInterface;
8
9
trait UnionTrait
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $unionAll = [];
15
16
    /**
17
     * @param QueryBuilderInterface $queryBuilder
18
     *
19
     * @return $this
20
     * @throws QueryBuilderException
21
     */
22
    public function unionAll(QueryBuilderInterface $queryBuilder)
23
    {
24
        if (CommandEnum::SELECT != $queryBuilder->commandData()) {
25
            throw new QueryBuilderException(\sprintf(
26
                '$queryBuilder should be with valid command! Valid command: "%s"',
27
                CommandEnum::SELECT
28
            ));
29
        }
30
31
        $this->unionAll[] = \sprintf('(%s)', $queryBuilder->buildQuery());
32
33
        $this->bind($queryBuilder->bindData());
0 ignored issues
show
Bug introduced by
It seems like bind() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $this->/** @scrutinizer ignore-call */ 
34
               bind($queryBuilder->bindData());
Loading history...
34
35
        return $this;
36
    }
37
38
    /**
39
     * @return null|string
40
     */
41
    protected function buildUnionAllQueryPart(): ?string
42
    {
43
        return empty($this->unionAll) ? null : \implode(' UNION ALL ', $this->unionAll);
44
    }
45
}
46