Publisher::publish()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 2
eloc 5
nc 2
nop 3
crap 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