Completed
Push — master ( d67629...d94fe1 )
by Changwan
03:26
created

FlushCommand::execute()   B

Complexity

Conditions 5
Paths 11

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 5
eloc 15
c 1
b 1
f 1
nc 11
nop 0
dl 0
loc 20
ccs 0
cts 20
cp 0
crap 30
rs 8.8571
1
<?php
2
namespace Wandu\Q\Commands;
3
4
use Psr\Log\LoggerInterface;
5
use Wandu\Console\Command;
6
use Wandu\Q\Queue;
7
8
class FlushCommand extends Command
9
{
10
    /** @var \Wandu\Q\Queue */
11
    protected $queue;
12
13
    /** @var \Psr\Log\LoggerInterface */
14
    protected $logger;
15
16
    public function __construct(Queue $queue, LoggerInterface $logger)
17
    {
18
        $this->queue = $queue;
19
        $this->logger = $logger;
20
    }
21
22
    function execute()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
23
    {
24
        try {
25
            while (1) {
26
                $job = $this->queue->dequeue();
27
                if (!isset($job)) {
28
                    return;
29
                }
30
                $payload = $job->read();
31
                $this->output->writeln("  Flush, " . print_r($payload, true));
32
                $job->delete();
33
            }
34
        } catch (\Exception $e) {
35
            $this->logger->alert($e);
36
            throw $e;
37
        } catch (\Throwable $e) {
38
            $this->logger->alert($e);
39
            throw $e;
40
        }
41
    }
42
}
43