Union::assemble()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5.2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 9
c 2
b 0
f 0
nc 16
nop 0
dl 0
loc 17
ccs 8
cts 10
cp 0.8
crap 5.2
rs 9.6111
1
<?php
2
3
namespace Nip\Database\Query\Select;
4
5
use Nip\Database\Query\Select;
6
7
class Union extends Select
8
{
9
    protected $_query1;
10
    protected $_query2;
11
12 1
    public function __construct($query1, $query2)
13
    {
14 1
        $this->_query1 = $query1;
15 1
        $this->_query2 = $query2;
16 1
    }
17
18 1
    public function assemble()
19
    {
20 1
        $query = ($this->_query1 instanceof Union) ? "(" . $this->_query1 . ")" : $this->_query1;
21 1
        $query .= " UNION ";
22 1
        $query .= ($this->_query2 instanceof Union) ? "(" . $this->_query2 . ")" : $this->_query2;
23
24 1
        $order = $this->parseOrder();
25
26 1
        if (!empty($order)) {
27
            $query .= " ORDER BY $order";
28
        }
29
30 1
        if (!empty($this->parts['limit'])) {
31
            $query .= " LIMIT {$this->parts['limit']}";
32
        }
33
34 1
        return $query;
35
    }
36
}
37