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

FlushCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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