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

FlushCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 35
ccs 0
cts 25
cp 0
rs 10
wmc 6
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B execute() 0 20 5
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