Completed
Push — master ( 186a7f...bab9dc )
by Gabriel
10:46
created

Union   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 30
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A assemble() 0 18 5
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
    public function __construct($query1, $query2)
13
    {
14
        $this->_query1 = $query1;
15
        $this->_query2 = $query2;
16
    }
17
18
    public function assemble()
19
    {
20
        $query = ($this->_query1 instanceof Union) ? "(" . $this->_query1 . ")" : $this->_query1;
21
        $query .= " UNION ";
22
        $query .= ($this->_query2 instanceof Union) ? "(" . $this->_query2 . ")" : $this->_query2;
23
24
        $order = $this->parseOrder();
25
26
        if (!empty($order)) {
27
            $query .= " ORDER BY $order";
28
        }
29
30
        if (!empty($this->parts['limit'])) {
31
            $query .= " LIMIT {$this->parts['limit']}";
32
        }
33
34
        return $query;
35
    }
36
}
37