PublishConfigsCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 1
A parseTagFromSelection() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Console\Commands;
6
7
use Hyde\Hyde;
8
use Hyde\Console\Concerns\Command;
9
use Illuminate\Support\Facades\Artisan;
10
11
use function array_search;
12
use function sprintf;
13
14
/**
15
 * Publish the Hyde config files.
16
 */
17
class PublishConfigsCommand extends Command
18
{
19
    /** @var string */
20
    protected $signature = 'publish:configs';
21
22
    /** @var string */
23
    protected $description = 'Publish the default configuration files';
24
25
    public function handle(): int
26
    {
27
        $options = [
28
            'All configs',
29
            '<comment>hyde-configs</comment>: Main configuration files',
30
            '<comment>support-configs</comment>: Laravel and package configuration files',
31
        ];
32
        $selection = $this->choice('Which configuration files do you want to publish?', $options, 'All configs');
33
34
        $tag = $this->parseTagFromSelection($selection, $options);
0 ignored issues
show
Bug introduced by
It seems like $selection can also be of type array; however, parameter $selection of Hyde\Console\Commands\Pu...parseTagFromSelection() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        $tag = $this->parseTagFromSelection(/** @scrutinizer ignore-type */ $selection, $options);
Loading history...
35
36
        Artisan::call('vendor:publish', [
37
            '--tag' => $tag,
38
            '--force' => true,
39
        ], $this->output);
40
41
        $this->infoComment(sprintf('Published config files to [%s]', Hyde::path('config')));
0 ignored issues
show
Bug introduced by
The method path() does not exist on Hyde\Hyde. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        $this->infoComment(sprintf('Published config files to [%s]', Hyde::/** @scrutinizer ignore-call */ path('config')));
Loading history...
42
43
        return Command::SUCCESS;
44
    }
45
46
    protected function parseTagFromSelection(string $selection, array $options): string
47
    {
48
        $tags = ['configs', 'hyde-configs', 'support-configs'];
49
50
        return $tags[array_search($selection, $options)];
51
    }
52
}
53