Passed
Push — v5 ( 6adbf6...c0775f )
by Alexey
06:03
created

Query::order()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 1
rs 10
c 0
b 0
f 0
ccs 0
cts 1
cp 0
crap 2
1
<?php
2
/**
3
 * Created by IntelliJ IDEA.
4
 * User: inji
5
 * Date: 07.01.2018
6
 * Time: 16:39
7
 */
8
9
namespace Inji\Db\InjiStorage;
10
11
use \Inji\Tools;
12
13
class Query implements \Inji\Db\DriverQuery {
14
    /**
15
     * @var \Inji\Db\InjiStorage
16
     */
17
    public $connection;
18
    public $whereArray = [];
19
    public $table = [];
20
    public $dbOptions = [];
21
    public $cols = [];
22
    public $colPrefix = '';
23
24 4
    public function __construct($connection) {
25 4
        $this->connection = $connection;
26 4
    }
27
28 4
    public function setDbOption($name, $value) {
29 4
        $this->dbOptions[$name] = $value;
30 4
    }
31
32
    public function cols($cols) {
33
        if (is_array($cols)) {
34
            $this->cols = array_merge($this->cols, array_values($cols));
35
        } else {
36
            $this->cols[] = $cols;
37
        }
38
    }
39
40 4
    public function colPrefix($colPrefix) {
41 4
        $this->colPrefix = $colPrefix;
42 4
    }
43
44
    public function limit($limit) {
45
        // TODO: Implement limit() method.
46
    }
47
48
    public function order($col, $direction = 'ASC') {
49
        // TODO: Implement order() method.
50
    }
51
52 4
    public function start($start) {
53
        // TODO: Implement start() method.
54 4
    }
55
56 4
    public function where($col, $value = true, $comparision = '=', $concatenation = 'AND') {
57 4
        if (is_array($col) && !Tools::isAssoc($col)) {
58 4
            $this->whereArray[] = $col;
59
        } else {
60
            $this->whereArray[] = [$col, $value, $comparision, $concatenation];
61
        }
62 4
        return $this;
63
    }
64
65 4
    public function setTable($tableName) {
66 4
        $this->table = $tableName;
67 4
    }
68
69 4
    public function select($tableName = null) {
70 4
        if (!$tableName) {
71 4
            $tableName = $this->table;
72
        }
73 4
        return new Result($this->connection->getItems($tableName, $this->cols, $this->whereArray, $this->dbOptions), $this);
74
    }
75
76 1
    public function insert(string $tableName, array $values) {
77 1
        if (!$tableName) {
78 1
            $tableName = $this->table;
79
        }
80 1
        return $this->connection->addItem($tableName, $values, $this->dbOptions);
81
    }
82
83 2
    public function update(string $tableName, array $values) {
84 2
        if (!$tableName) {
85 2
            $tableName = $this->table;
86
        }
87 2
        return $this->connection->updateItems($tableName, $this->whereArray, $values, $this->dbOptions);
88
    }
89
90 1
    public function delete(string $tableName = '') {
91 1
        if (!$tableName) {
92 1
            $tableName = $this->table;
93
        }
94 1
        return $this->connection->deleteItems($tableName, $this->whereArray, $this->dbOptions);
95
    }
96
97
}