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

BeanstalkdAdapter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A enqueue() 0 4 1
A dequeue() 0 8 2
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