Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
PublishConfigsCommand
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 handle
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
1
 parseTagFromSelection
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Hyde\Console\Commands;
6
7use Hyde\Hyde;
8use Hyde\Console\Concerns\Command;
9use Illuminate\Support\Facades\Artisan;
10
11use function array_search;
12use function sprintf;
13
14/**
15 * Publish the Hyde config files.
16 */
17class 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);
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')));
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}