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

BeanstalkdAdapter::enqueue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
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