Consumer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 40
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A consume() 0 14 2
1
<?php
2
3
namespace Equip\RedisQueue;
4
5
use Predis\Client;
6
use Relay\ResolverInterface;
7
8
class Consumer
9
{
10
    /**
11
     * @var Client
12
     */
13
    private $client;
14
15
    /**
16
     * @var ResolverInterface
17
     */
18
    private $resolver;
19
20
    /** 
21
     * @param Client $client
22
     * @param ResolverInterface $resolver
23
     */
24 2
    public function __construct(Client $client, ResolverInterface $resolver)
25
    {
26 2
        $this->client = $client;
27 2
        $this->resolver = $resolver;
28 2
    }
29
30
    /**
31
     * @param string $queue
32
     */
33 2
    public function consume($queue)
34
    {
35 2
        $value = $this->client->lpop($queue);
36 2
        if ($value === null) {
37 1
            return;
38
        }
39
40 1
        $decoded = json_decode($value, true);
41 1
        $command = call_user_func($this->resolver, $decoded['command']);
42
43
        $command
44 1
            ->withOptions($decoded['options'])
45 1
            ->execute();
46 1
    }
47
}
48