Completed
Push — master ( e0c858...9a1ea4 )
by Adam
13:47
created

BeanstalkDriver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 50
ccs 18
cts 18
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A enqueue() 0 6 1
A processed() 0 4 1
A dequeue() 0 13 2
1
<?php
2
3
namespace Equip\Queue\Driver;
4
5
use Pheanstalk\Job;
6
use Pheanstalk\Pheanstalk;
7
8
class BeanstalkDriver implements DriverInterface
9
{
10
    /**
11
     * @var Pheanstalk
12
     */
13
    private $beanstalk;
14
15
    /**
16
     * @param Pheanstalk $beanstalk
17
     */
18 4
    public function __construct(Pheanstalk $beanstalk)
19
    {
20 4
        $this->beanstalk = $beanstalk;
21 4
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26 1
    public function enqueue($queue, $command)
27
    {
28 1
        return (boolean) $this->beanstalk
29 1
            ->useTube($queue)
30 1
            ->put(serialize($command));
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36 2
    public function dequeue($queue)
37
    {
38 2
        $job = $this->beanstalk
39 2
            ->watch($queue)
40 2
            ->ignore('default')
41 2
            ->reserve(static::TIMEOUT);
42
43 2
        $data = $job instanceof Job ? $job->getData() : $job;
44
        return [
45 2
            unserialize($data),
46 2
            $job,
47 2
        ];
48
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53 1
    public function processed($job)
54
    {
55 1
        return (boolean) $this->beanstalk->delete($job);
56
    }
57
}
58