Test Failed
Push — master ( 159af9...b2d1de )
by Banciu N. Cristian Mihai
03:26
created

DeleteAllCommand::handleInternal()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 43
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 43
rs 9.7666
cc 3
nc 4
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 DeleteAllCommand
11
 */
12
class DeleteAllCommand extends BaseCommand
13
{
14
15
    /**
16
     * The name and signature of the console command.
17
     *
18
     * @var string
19
     */
20
    protected $signature = 'carrot-mq:delete-all';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Delete all queues and topics';
28
29
    /**
30
     * Execute the console command.
31
     *
32
     * @return integer
33
     */
34
    public function handleInternal()
35
    {
36
        /*
37
        |--------------------------------------------------------------------------
38
        | Topics
39
        |--------------------------------------------------------------------------
40
        |
41
        */
42
        foreach ($this->carrot->container()->topics()->all() as $entity) {
43
            $entity->delete();
44
45
            $this->output->writeln(
46
                vsprintf(
47
                    'Deleted TOPIC <info>%s</info> - <fg=yellow>%s</>',
48
                    [
49
                        $entity->id(),
50
                        $entity->name(),
51
                    ]
52
                )
53
            );
54
        }
55
56
        /*
57
        |--------------------------------------------------------------------------
58
        | Queues
59
        |--------------------------------------------------------------------------
60
        |
61
        */
62
        foreach ($this->carrot->container()->queues()->all() as $entity) {
63
            $entity->delete();
64
65
            $this->output->writeln(
66
                vsprintf(
67
                    'Deleted QUEUE <info>%s</info> - <fg=yellow>%s</>',
68
                    [
69
                        $entity->id(),
70
                        $entity->name(),
71
                    ]
72
                )
73
            );
74
        }
75
76
        return 0;
77
    }
78
79
}
80