BeanstalkdQueueStoreConnection::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Da\Mailer\Queue\Backend\Beanstalkd;
4
5
use Da\Mailer\Queue\Backend\AbstractQueueStoreConnection;
6
use Pheanstalk\Connection;
7
use Pheanstalk\Pheanstalk;
8
use Pheanstalk\SocketFactory;
9
10
class BeanstalkdQueueStoreConnection extends AbstractQueueStoreConnection
11
{
12
    /**
13
     * BeanstalkdQueueStoreConnection constructor.
14
     *
15
     * @param array $configuration
16 3
     *
17
     * @see connect for options
18 3
     */
19 3
    public function __construct(array $configuration)
20
    {
21
        parent::__construct($configuration);
22
    }
23
24 2
    /**
25
     * @return BeanstalkdQueueStoreConnection
26 2
     */
27 2
    public function connect()
28 2
    {
29 2
        $this->disconnect();
30 2
        $host = $this->getConfigurationValue('host', '127.0.0.1');
31 2
        $port = $this->getConfigurationValue('port', Pheanstalk::DEFAULT_PORT);
32
        $connectionTimeout = $this->getConfigurationValue('connectionTimeout');
33 2
        $connectPersistent = $this->getConfigurationValue('connectPersistent', false);
34
        $connection = new Connection(new SocketFactory($host, $port ?: Pheanstalk::DEFAULT_PORT, $connectionTimeout ?? 0, $connectPersistent ?? SocketFactory::AUTODETECT));
35
        $this->instance = new Pheanstalk($connection);
36
        return $this;
37
    }
38
39 1
    /**
40
     * @return Pheanstalk
41 1
     */
42 1
    public function getInstance()
43 1
    {
44
        if ($this->instance === null) {
45 1
            $this->connect();
46
        }
47
48
        return $this->instance;
49
    }
50
}
51