MongoHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createQueue() 0 8 1
A reset() 0 4 1
A clear() 0 4 1
A configure() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the Phive Queue package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phive\Queue\Tests\Handler;
13
14
use Phive\Queue\MongoQueue;
15
16
class MongoHandler extends Handler
17
{
18
    /**
19
     * @var \MongoClient
20
     */
21
    private $mongoClient;
22
23
    /**
24
     * @var \MongoCollection
25
     */
26
    private $coll;
27
28
    public function createQueue()
29
    {
30
        return new MongoQueue(
31
            $this->mongoClient,
32
            $this->getOption('db_name'),
33
            $this->getOption('coll_name')
34
        );
35
    }
36
37
    public function reset()
38
    {
39
        $this->mongoClient->selectDB($this->getOption('db_name'))->drop();
40
    }
41
42
    public function clear()
43
    {
44
        $this->coll->remove();
45
    }
46
47
    protected function configure()
48
    {
49
        $this->mongoClient = new \MongoClient($this->getOption('server'));
50
        $this->coll = $this->mongoClient->selectCollection($this->getOption('db_name'), $this->getOption('coll_name'));
51
        $this->coll->ensureIndex(['eta' => 1]);
52
    }
53
}
54