SetupCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
eloc 32
c 3
b 0
f 0
dl 0
loc 95
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handleInternal() 0 73 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BinaryCube\CarrotMQ\Support\Laravel\Console\Commands;
6
7
use Illuminate\Support\Facades\Log;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Facades\Log was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
use function vsprintf;
10
11
/**
12
 * Class SetupCommand
13
 */
14
class SetupCommand extends BaseCommand
15
{
16
17
    /**
18
     * The name and signature of the console command.
19
     *
20
     * @var string
21
     */
22
    protected $signature = 'carrot-mq:setup {--force}';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Create all queues and topics';
30
31
    /**
32
     * @return int
33
     *
34
     * @throws \Exception
35
     */
36
    protected function handleInternal()
37
    {
38
        $force = $this->input->getOption('force');
39
40
        /*
41
        |--------------------------------------------------------------------------
42
        | Topics
43
        |--------------------------------------------------------------------------
44
        |
45
        */
46
        foreach ($this->carrot->container()->topics()->all() as $entity) {
47
            if ($force) {
48
                $entity->delete();
49
50
                $this->output->writeln(
51
                    vsprintf(
52
                        'Deleted TOPIC <info>%s</info> - <fg=yellow>%s</>',
53
                        [
54
                            $entity->id(),
55
                            $entity->name(),
56
                        ]
57
                    )
58
                );
59
            }
60
61
            $entity->install();
62
63
            $this->output->writeln(
64
                vsprintf(
65
                    'Created <info>TOPIC</info> <fg=yellow>%s</> - <fg=yellow>%s</>',
66
                    [
67
                        $entity->name(),
68
                        $entity->id(),
69
                    ]
70
                )
71
            );
72
        }//end foreach
73
74
        /*
75
        |--------------------------------------------------------------------------
76
        | Queues
77
        |--------------------------------------------------------------------------
78
        |
79
        */
80
        foreach ($this->carrot->container()->queues()->all() as $entity) {
81
            if ($force) {
82
                $entity->delete();
83
84
                $this->output->writeln(
85
                    vsprintf(
86
                        'Deleted QUEUE <info>%s</info> - <fg=yellow>%s</>',
87
                        [
88
                            $entity->id(),
89
                            $entity->name(),
90
                        ]
91
                    )
92
                );
93
            }
94
95
            $entity->install();
96
97
            $this->output->writeln(
98
                vsprintf(
99
                    'Created <info>QUEUE</info> <fg=yellow>%s</> - <fg=yellow>%s</>',
100
                    [
101
                        $entity->name(),
102
                        $entity->id(),
103
                    ]
104
                )
105
            );
106
        }//end foreach
107
108
        return 0;
109
    }
110
111
}
112