UpdateAll   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 31 4
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ReliqArts\Docweaver\Console\Command;
6
7
use Carbon\Carbon;
8
use Illuminate\Console\Command;
9
use ReliqArts\Docweaver\Contract\Documentation\Publisher;
10
use stdClass;
11
12
class UpdateAll extends Command
13
{
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'docweaver:update-all
20
                            {--y|y : Whether to skip confirmation}
21
                            ';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Update documentation for all products';
29
30
    /**
31
     * @var Publisher
32
     */
33
    protected $publisher;
34
35
    /**
36
     * Create a new command instance.
37
     */
38
    public function __construct(Publisher $publisher)
39
    {
40
        parent::__construct();
41
42
        $this->publisher = $publisher;
43
    }
44
45
    /**
46
     * Execute the console command.
47
     */
48
    public function handle(): void
49
    {
50
        $skipConfirmation = $this->option('y');
51
        $confirmationMessage = 'This command will attempt to update documentation for all products.'
52
            . "\nPlease ensure your internet connection is stable. Ready?";
53
54
        $this->comment(PHP_EOL
55
            . "<info>♣♣♣</info> Docweaver DocumentationPublisher \n"
56
            . 'Help is here, try: php artisan docweaver:update-all --help');
57
58
        if ($skipConfirmation || $this->confirm($confirmationMessage)) {
59
            $this->info("Updating products.\nT: " . Carbon::now()->toCookieString() . "\n----------");
60
61
            $result = $this->publisher->updateAll($this);
62
63
            if (!$result->isSuccess()) {
64
                $this->line(PHP_EOL . "<error>✘</error> {$result->getError()}");
65
66
                return;
67
            }
68
69
            $this->info(PHP_EOL . '----------');
70
            $this->comment("<info>✔</info> Done. {$result->getMessage()}");
71
72
            // Display results
73
            $this->line('');
74
            $headers = ['Time', 'Products', 'Updated'];
75
            $data = $result->getExtra() ?? new stdClass();
76
            $rows = [[$data->executionTime ?? '?', count($data->products ?? []), count($data->productsUpdated ?? [])]];
77
            $this->table($headers, $rows);
78
            $this->line(PHP_EOL);
79
        }
80
    }
81
}
82