Daemon::run()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
cc 3
eloc 8
nc 3
nop 0
crap 3
1
<?php
2
3
namespace Equip\RedisQueue;
4
5
use Aura\Cli\Stdio;
6
use Aura\Cli\Context;
7
use Aura\Cli\Status;
8
9
class Daemon
10
{
11
    /**
12
     * @var Consumer
13
     */
14
    private $consumer;
15
16
    /**
17
     * @var Stdio
18
     */
19
    private $stdio;
20
21
    /**
22
     * @var Context
23
     */
24
    private $context;
25
26
    /**
27
     * @var callable
28
     */
29
    private $listener;
30
31
    /**
32
     * @param Consumer $consumer
33
     * @param Stdio $stdio
34
     * @param Context $context
35
     */
36 2
    public function __construct(
37
        Consumer $consumer,
38
        Stdio $stdio,
39
        Context $context
40
    )
41
    {
42 2
        $this->consumer = $consumer;
43 2
        $this->stdio = $stdio;
44 2
        $this->context = $context;
45
46
        $this->setListener(function () { return true; });
0 ignored issues
show
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
47 2
    }
48
49
    /**
50
     * @param callable $listener
51
     */
52 2
    public function setListener(callable $listener)
53
    {
54 2
        $this->listener = $listener;
55 2
    }
56
57
    /**
58
     * @return int Status code to exit with
59
     */
60 2
    public function run()
61
    {
62 2
        $queue = $this->context->argv->get(1);
63 2
        if (!$queue) {
64 1
            $this->stdio->outln('<<red>>No queue specified<<reset>>');
65 1
            return Status::USAGE;
66
        }
67
68 1
        while (call_user_func($this->listener)) {
69 1
            $this->consumer->consume($queue);
70 1
        }
71 1
        return Status::SUCCESS;
72
    }
73
}
74