Passed
Push — master ( 2d5d29...0740c8 )
by ReliQ
04:50 queued 13s
created

SingleProductCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 19
dl 0
loc 39
rs 10
c 1
b 1
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A displayResult() 0 22 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ReliqArts\Docweaver\Console\Command;
6
7
use Illuminate\Console\Command;
8
use ReliqArts\Docweaver\Contract\Documentation\Publisher;
9
use ReliqArts\Docweaver\Result;
10
use stdClass;
11
12
abstract class SingleProductCommand extends Command
13
{
14
    /**
15
     * @var Publisher
16
     */
17
    protected Publisher $publisher;
18
19
    /**
20
     * Create a new command instance.
21
     */
22
    public function __construct(Publisher $publisher)
23
    {
24
        parent::__construct();
25
26
        $this->publisher = $publisher;
27
    }
28
29
    protected function displayResult(Result $result): void
30
    {
31
        if (!$result->isSuccess()) {
32
            $this->line(PHP_EOL . "<error>✘</error> {$result->getError()}");
33
34
            return;
35
        }
36
37
        $this->info(PHP_EOL . '----------');
38
        $this->comment("<info>✔</info> Done. {$result->getMessage()}");
39
40
        $this->line('');
41
        $headers = ['Time', 'Versions', 'Published', 'Updated'];
42
        $data = $result->getExtra() ?? new stdClass();
43
        $rows = [[
44
            $data->executionTime ?? '?',
45
            count($data->versions ?? []),
46
            count($data->versionsPublished ?? []),
47
            count($data->versionsUpdated ?? []),
48
        ]];
49
        $this->table($headers, $rows);
50
        $this->line(PHP_EOL);
51
    }
52
}
53