Connection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 51
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 7 2
A createCommand() 0 8 1
A getQueryBuilder() 0 4 1
1
<?php
2
/**
3
 *
4
 * @author Mihkel Viilveer <[email protected]>
5
 * @date 25.08.2014
6
 */
7
8
namespace opus\elastic\components;
9
10
use yii\base\InvalidParamException;
11
use yii\caching\Cache;
12
13
/**
14
 * Class Connection
15
 *
16
 * @author Mihkel Viilveer <[email protected]>
17
 * @package common\components\elasticsearch
18
 */
19
class Connection extends \yii\elasticsearch\Connection
20
{
21
    /**
22
     * @var Cache|string the cache object or the ID of the cache application component
23
     * that is used for query caching.
24
     */
25
    public $cache = 'cache';
26
27
    /**
28
     * Spooler table name
29
     * @var string
30
     */
31
    public $spoolerTableName = '{{ym_elastic_spool_item}}';
32
33
    /**
34
     * Elastic search index name
35
     * @var string
36
     */
37
    public $index;
38
39
    public function init()
40
    {
41
        parent::init();
42
        if (is_null($this->index)) {
43
            throw new InvalidParamException('Property "index" must be set');
44
        }
45
    }
46
47
    /**
48
     * Creates a command for execution.
49
     * @param array $config the configuration for the Command class
50
     * @return Command the DB command
51
     */
52
    public function createCommand($config = [])
53
    {
54
        $this->open();
55
        $config['db'] = $this;
56
        $command = new Command($config);
57
58
        return $command;
59
    }
60
61
    /**
62
     * Creates new query builder instance
63
     * @return QueryBuilder
64
     */
65
    public function getQueryBuilder()
66
    {
67
        return new QueryBuilder($this);
68
    }
69
}