Completed
Push — master ( e15c58...b150a8 )
by Changwan
07:08
created

BeanstalkdAdapter::dequeue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 8
ccs 0
cts 8
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Q\Adapter;
3
4
use Pheanstalk\PheanstalkInterface;
5
use Wandu\Q\Contracts\AdapterInterface;
6
use Wandu\Q\Contracts\SerializerInterface;
7
use Wandu\Q\Job\BeanstalkdJob;
8
9
class BeanstalkdAdapter implements AdapterInterface
10
{
11
    /** @var \Pheanstalk\PheanstalkInterface */
12
    protected $client;
13
14
    /**
15
     * @param \Pheanstalk\PheanstalkInterface $client
16
     */
17
    public function __construct(PheanstalkInterface $client)
18
    {
19
        $this->client = $client;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function enqueue(SerializerInterface $serializer, $payload)
26
    {
27
        $this->client->put($serializer->serialize($payload));
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function dequeue(SerializerInterface $serializer)
34
    {
35
        $job = $this->client->reserve();
36
        if ($job) {
37
            return new BeanstalkdJob($this->client, $job, $serializer);
38
        }
39
        return null;
40
    }
41
}
42