Completed
Push — master ( 4484cf...67cb35 )
by Dmitry
02:58
created

Clickhouse   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 95.24%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 46
ccs 20
cts 21
cp 0.9524
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B select() 0 23 4
A insert() 0 15 3
1
<?php
2
3
namespace Basis;
4
5
use ClickHouseDB\Client;
6
7
class Clickhouse
8
{
9
    use Toolkit;
10
11
    public $bucketSize = 1000;
12
13 2
    public function select($fields, string $table, array $params = [])
14
    {
15 2
        if (is_array($fields)) {
16
            $fields = implode(', ', $fields);
17
        }
18
19 2
        $query = "SELECT $fields FROM $table";
20 2
        $binds = [];
21
22 2
        if (count($params)) {
23 1
            $where = [];
24 1
            foreach ($params as $k => $v) {
25 1
                $binds[$k] = (array) $v;
26 1
                $where[] = $k.' in (:'.$k.')';
27
            }
28
29 1
            $where = implode(' and ', $where);
30
31 1
            $query .= " where $where";
32
        }
33
34 2
        return $this->get(Client::class)->select($query, $binds);
35
    }
36
37 2
    public function insert(string $table, array $data, array $headers)
0 ignored issues
show
Unused Code introduced by
The parameter $table is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39 2
        $client = $this->get(Client::class);
40 2
        if (count($data) < $this->bucketSize) {
41 2
            $buckets = [$data];
42
        } else {
43 1
            $buckets = array_chunk($data, $this->bucketSize);
44
        }
45
46 2
        foreach ($buckets as $bucket) {
47 2
            $client->insert('tester', $bucket, $headers);
48
        }
49
50 2
        return count($buckets);
51
    }
52
}
53