Completed
Push — master ( 3fdc21...2574b5 )
by ReliQ
01:51
created

UpdateAll   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 70
rs 10
c 0
b 0
f 0

2 Methods

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