Completed
Push — master ( 9eae13...e56856 )
by Antonio
04:26
created

BeanstalkdQueueStoreConnection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 41
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A connect() 0 11 1
A getInstance() 0 8 2
1
<?php
2
namespace Da\Mailer\Queue\Backend\Beanstalk;
3
4
use Da\Mailer\Queue\Backend\AbstractQueueStoreConnection;
5
use Pheanstalk\Pheanstalk;
6
7
class BeanstalkdQueueStoreConnection extends AbstractQueueStoreConnection
8
{
9
    /**
10
     * BeanstalkdQueueStoreConnection constructor.
11
     *
12
     * @param array $configuration
13
     *
14
     * @see connect for options
15
     */
16 3
    public function __construct(array $configuration)
17
    {
18 3
        parent::__construct($configuration);
19 3
    }
20
21
    /**
22
     * @return BeanstalkdQueueStoreConnection
23
     */
24 2
    public function connect()
25
    {
26 2
        $this->disconnect();
27 2
        $host = $this->getConfigurationValue('host', '127.0.0.1');
28 2
        $port = $this->getConfigurationValue('port', Pheanstalk::DEFAULT_PORT);
29 2
        $connectionTimeout = $this->getConfigurationValue('connectionTimeout');
30 2
        $connectPersistent = $this->getConfigurationValue('connectPersistent', false);
31 2
        $this->instance = new Pheanstalk($host, $port, $connectionTimeout, $connectPersistent);
32
33 2
        return $this;
34
    }
35
36
    /**
37
     * @return Pheanstalk
38
     */
39 1
    public function getInstance()
40
    {
41 1
        if ($this->instance === null) {
42 1
            $this->connect();
43 1
        }
44
45 1
        return $this->instance;
46
    }
47
}
48