PurgeCommand::handleInternal()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 14
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BinaryCube\CarrotMQ\Support\Laravel\Console\Commands;
6
7
use function vsprintf;
8
9
/**
10
 * Class PurgeCommand
11
 */
12
class PurgeCommand extends BaseCommand
13
{
14
15
    /**
16
     * The name and signature of the console command.
17
     *
18
     * @var string
19
     */
20
    protected $signature = 'carrot-mq:purge {queue}';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Delete all messages from the queue';
28
29
    /**
30
     * Execute the console command.
31
     *
32
     * @return integer
33
     *
34
     * @throws \Exception
35
     */
36
    public function handleInternal()
37
    {
38
        $queueId = (string) $this->input->getArgument('queue');
39
40
        if (! $this->carrot->container()->queues()->has($queueId)) {
41
            $this->error(vsprintf('Queue "%s" not found.', [$queueId]));
42
            return 0;
43
        }
44
45
        $queue = $this->carrot->container()->queues()->get($queueId);
46
47
        $queue->purge();
48
49
        return 0;
50
    }
51
52
}
53