CDNCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 5
1
<?php
2
3
namespace Bavix\CupKit\Commands;
4
5
use Bavix\CupKit\Client;
6
use Bavix\CupKit\CupKitServiceProvider;
7
use Illuminate\Console\Command;
8
9
class CDNCommand extends Command
10
{
11
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'cdn:init';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Creates a view in corundum';
25
26
    /**
27
     * Execute the console command.
28
     *
29
     * @return void
30
     */
31
    public function handle(): void
32
    {
33
        /**
34
         * @var Client $cup
35
         */
36
        $cup = app(CupKitServiceProvider::SINGLETON_CLIENT);
37
        foreach (config('corundum.buckets', []) as $bucketName => $views) {
38
            try {
39
                $cup->createBucket($bucketName);
40
                $this->info("Bucket $bucketName create");
41
            } catch (\Throwable $throwable) {
42
                $this->warn("Bucket $bucketName exists");
43
            } finally {
44
                foreach ($views as $view) {
45
                    try {
46
                        $cup->createView($bucketName, $view);
47
                        $this->info("View $bucketName.{$view['name']} create");
48
                    } catch (\Throwable $throwable) {
49
                        $this->warn("View $bucketName.{$view['name']} exists");
50
                    }
51
                }
52
            }
53
        }
54
    }
55
56
}
57