Publisher   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
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 30
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A publish() 0 9 2
1
<?php
2
3
namespace Equip\RedisQueue;
4
5
use Equip\Command\CommandInterface;
6
use Predis\Client;
7
8
class Publisher
9
{
10
    /**
11
     * @var Client
12
     */
13
    private $client;
14
15
    /** 
16
     * @param Client $client
17
     */
18 2
    public function __construct(Client $client)
19
    {
20 2
        $this->client = $client;
21 2
    }
22
23
    /**
24
     * @param string $queue Name of the queue to receive the job
25
     * @param string $command FQCN for Command class to be executed by the job
26
     * @param array $options Options for the Command class instance
27
     */
28 2
    public function publish($queue, $command, array $options = [])
29
    {
30 2
        if (!is_subclass_of($command, CommandInterface::class)) {
31 1
            throw new \RuntimeException('Class does not implement CommandInterface: ' . $command);
32
        }
33
34 1
        $job = json_encode(['command' => $command, 'options' => $options]);
35 1
        $this->client->rpush($queue, $job);
36 1
    }
37
}
38