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 Update extends Command |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The name and signature of the console command. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $signature = 'docweaver:update |
19
|
|
|
{product? : Product name} |
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 product'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Publisher |
32
|
|
|
*/ |
33
|
|
|
protected $publisher; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Create a new command instance. |
37
|
|
|
* |
38
|
|
|
* @param Publisher $publisher |
39
|
|
|
*/ |
40
|
|
|
public function __construct(Publisher $publisher) |
41
|
|
|
{ |
42
|
|
|
parent::__construct(); |
43
|
|
|
|
44
|
|
|
$this->publisher = $publisher; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Execute the console command. |
49
|
|
|
*/ |
50
|
|
|
public function handle(): void |
51
|
|
|
{ |
52
|
|
|
$productName = $this->argument('product'); |
53
|
|
|
$skipConfirmation = $this->option('y'); |
54
|
|
|
$confirmationMessage = sprintf( |
55
|
|
|
"This command will attempt to update documentation for product (%s). \n" |
56
|
|
|
. 'Please ensure your internet connection is stable. Ready?', |
57
|
|
|
$productName |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$this->comment(PHP_EOL |
61
|
|
|
. "<info>♣♣♣</info> Docweaver DocumentationPublisher \n" |
62
|
|
|
. 'Help is here, try: php artisan docweaver:update --help'); |
63
|
|
|
|
64
|
|
View Code Duplication |
if ($skipConfirmation || $this->confirm($confirmationMessage)) { |
|
|
|
|
65
|
|
|
$this->info("Updating {$productName}.\nT: " . Carbon::now()->toCookieString() . "\n----------"); |
66
|
|
|
|
67
|
|
|
$result = $this->publisher->update($productName, $this); |
|
|
|
|
68
|
|
|
|
69
|
|
|
if ($result->isSuccess()) { |
70
|
|
|
$this->info(PHP_EOL . '----------'); |
71
|
|
|
$this->comment("<info>✔</info> Done. {$result->getMessage()}"); |
72
|
|
|
|
73
|
|
|
// Display results |
74
|
|
|
$this->line(''); |
75
|
|
|
$headers = ['Time', 'Versions', 'Published', 'Updated']; |
76
|
|
|
$data = $result->getData(); |
77
|
|
|
$rows = [[ |
78
|
|
|
$data->executionTime, |
79
|
|
|
count($data->versions), |
80
|
|
|
count($data->versionsPublished), |
81
|
|
|
count($data->versionsUpdated), |
82
|
|
|
]]; |
83
|
|
|
$this->table($headers, $rows); |
84
|
|
|
$this->line(PHP_EOL); |
85
|
|
|
} else { |
86
|
|
|
$this->line(PHP_EOL . "<error>✘</error> {$result->getError()}"); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.