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

Update::handle()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 40

Duplication

Lines 25
Ratio 62.5 %

Importance

Changes 0
Metric Value
dl 25
loc 40
rs 9.28
c 0
b 0
f 0
cc 4
nc 3
nop 0
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)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
65
            $this->info("Updating {$productName}.\nT: " . Carbon::now()->toCookieString() . "\n----------");
66
67
            $result = $this->publisher->update($productName, $this);
0 ignored issues
show
Bug introduced by
It seems like $productName defined by $this->argument('product') on line 52 can also be of type array or null; however, ReliqArts\Docweaver\Cont...ion\Publisher::update() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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