MongoConnector::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace SfCod\QueueBundle\Connector;
4
5
use SfCod\QueueBundle\Base\JobResolverInterface;
6
use SfCod\QueueBundle\Queue\MongoQueue;
7
use SfCod\QueueBundle\Queue\QueueInterface;
8
use SfCod\QueueBundle\Service\MongoDriver;
9
10
/**
11
 * Connector for queue to mongodb
12
 *
13
 * @author Orlov Aleksey <[email protected]>
14
 * @author Virchenko Maksim <[email protected]>
15
 */
16
class MongoConnector implements ConnectorInterface
17
{
18
    /**
19
     * @var JobResolverInterface
20
     */
21
    protected $jobResolver;
22
23
    /**
24
     * @var MongoDriver
25
     */
26
    protected $mongo;
27
28
    /**
29
     * MongoConnector constructor.
30
     *
31
     * @param JobResolverInterface $jobResolver
32
     * @param MongoDriver $mongo
33
     */
34
    public function __construct(JobResolverInterface $jobResolver, MongoDriver $mongo)
35
    {
36
        $this->jobResolver = $jobResolver;
37
        $this->mongo = $mongo;
38
    }
39
40
    /**
41
     * Establish a queue database.
42
     *
43
     * @param array $config
44
     *
45
     * @return QueueInterface
46
     */
47
    public function connect(array $config): QueueInterface
48
    {
49
        $config = array_merge([
50
            'limit' => 15,
51
        ], $config);
52
53
        $queue = new MongoQueue(
54
            $this->jobResolver,
55
            $this->mongo,
56
            $config['collection'],
57
            $config['queue'],
58
            $config['expire'],
59
            $config['limit']
60
        );
61
62
        return $queue;
63
    }
64
}
65