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

BeanstalkdQueueStoreConnection::connect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
crap 1
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