Completed
Push — master ( 8eb315...5aaba6 )
by Changwan
04:29
created

Queue   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 45
ccs 13
cts 14
cp 0.9286
rs 10
wmc 6
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A flush() 0 4 1
A send() 0 4 1
A receive() 0 6 2
1
<?php
2
namespace Wandu\Q;
3
4
use Wandu\Q\Contracts\Adapter;
5
use Wandu\Q\Contracts\Serializer;
6
use Wandu\Q\Serializer\JsonSerializer;
7
8
class Queue
9
{
10
    /** @var \Wandu\Q\Contracts\Adapter */
11
    protected $adapter;
12
13
    /** @var \Wandu\Q\Contracts\Serializer */
14
    protected $serializer;
15
16
    /**
17
     * @param \Wandu\Q\Contracts\Serializer $serializer
18
     * @param \Wandu\Q\Contracts\Adapter $adapter
19
     */
20 2
    public function __construct(Adapter $adapter, Serializer $serializer = null)
21
    {
22 2
        $this->adapter = $adapter;
23 2
        $this->serializer = $serializer ?: new JsonSerializer();
24 2
    }
25
26
    /**
27
     * @return void 
28
     */
29 1
    public function flush()
30
    {
31 1
        $this->adapter->flush();
32 1
    }
33
34
    /**
35
     * @param mixed $message
36
     * @return void
37
     */
38 2
    public function send($message)
39
    {
40 2
        $this->adapter->send($this->serializer->serialize($message));
41 2
    }
42
43
    /**
44
     * @return \Wandu\Q\Job
45
     */
46 2
    public function receive()
47
    {
48 2
        if ($job = $this->adapter->receive()) {
49 2
            return new Job($this->adapter, $this->serializer, $job);
50
        }
51
    }
52
}
53