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

BeanstalkDriver::enqueue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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