Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
HydePublishViewsCommand
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
5 / 5
10
100.00% covered (success)
100.00%
1 / 1
 handle
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
 publishOption
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 promptForCategory
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 formatPublishableChoices
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 parseChoiceIntoKey
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Hyde\Framework\Commands;
4
5use Hyde\Framework\Actions\PublishesHydeViews;
6use Hyde\Framework\Hyde;
7use LaravelZero\Framework\Commands\Command;
8
9/**
10 * Publish the Hyde Blade views.
11 */
12class HydePublishViewsCommand extends Command
13{
14    protected $signature = 'publish:views {category? : The category to publish}';
15
16    protected $description = 'Publish the hyde components for customization. Note that existing files will be overwritten.';
17
18    protected string $selected;
19
20    public function handle(): int
21    {
22        $this->selected = $this->argument('category') ?? $this->promptForCategory();
23
24        if ($this->selected === 'all' || $this->selected === '') {
25            foreach (PublishesHydeViews::$options as $key => $value) {
26                $this->publishOption($key);
27            }
28        } else {
29            $this->publishOption($this->selected);
30        }
31
32        return 0;
33    }
34
35    protected function publishOption($selected)
36    {
37        (new PublishesHydeViews($selected))->execute();
38
39        $from = Hyde::vendorPath(PublishesHydeViews::$options[$selected]['path']);
40        $from = substr($from, strpos($from, 'vendor'));
41
42        $to = (PublishesHydeViews::$options[$selected]['destination']);
43
44        $this->line('<info>Copied</info> ['."<comment>$from</comment>".'] <info>to</info> ['."<comment>$to</comment>".']');
45    }
46
47    protected function promptForCategory(): string
48    {
49        $choice = $this->choice(
50            'Which category do you want to publish?',
51            $this->formatPublishableChoices(),
52            0
53        );
54
55        $choice = $this->parseChoiceIntoKey($choice);
56
57        $this->line('<info>Selected category</info> [<comment>'.(empty($choice) ? 'all' : $choice).'</comment>]');
58        $this->newLine();
59
60        return $choice;
61    }
62
63    protected function formatPublishableChoices(): array
64    {
65        $keys = [];
66        $keys[] = 'Publish all categories listed below';
67        foreach (PublishesHydeViews::$options as $key => $value) {
68            $keys[] = "<comment>$key</comment>: {$value['description']}";
69        }
70
71        return $keys;
72    }
73
74    protected function parseChoiceIntoKey(string $choice): string
75    {
76        return strstr(str_replace(['<comment>', '</comment>'], '', $choice), ':', true);
77    }
78}