Passed
Push — master ( 2498e7...b2219c )
by Caen
13:03 queued 13s
created

VendorPublishCommand::status()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 7
b 0
f 0
nc 1
nop 3
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Console\Commands;
6
7
use Hyde\Hyde;
8
use Illuminate\Foundation\Console\VendorPublishCommand as BaseCommand;
9
use Illuminate\Support\ServiceProvider;
10
use NunoMaduro\LaravelConsoleSummary\LaravelConsoleSummaryServiceProvider;
11
use function ltrim;
12
use function realpath;
13
use function sprintf;
14
use function str_replace;
15
16
/**
17
 * Publish any publishable assets from vendor packages.
18
 *
19
 * @see \Hyde\Framework\Testing\Feature\Commands\VendorPublishCommandTest
20
 */
21
class VendorPublishCommand extends BaseCommand
22
{
23
    /**
24
     * Our child method filters the options available to the parent method.
25
     */
26
    public function handle(): void
27
    {
28
        $originalPublishers = ServiceProvider::$publishes;
29
        $originalGroups = ServiceProvider::$publishGroups;
30
31
        // This provider's publisher is not needed as it's covered by Laravel Zero
32
        unset(ServiceProvider::$publishes[LaravelConsoleSummaryServiceProvider::class]);
33
34
        // Rename the config group to be more helpful
35
        if (isset(ServiceProvider::$publishGroups['config'])) {
36
            ServiceProvider::$publishGroups['vendor-configs'] = ServiceProvider::$publishGroups['config'];
37
            unset(ServiceProvider::$publishGroups['config']);
38
        }
39
40
        parent::handle();
41
42
        ServiceProvider::$publishes = $originalPublishers;
43
        ServiceProvider::$publishGroups = $originalGroups;
44
    }
45
46
    /**
47
     * Write a status message to the console.
48
     *
49
     * @param  string  $from
50
     * @param  string  $to
51
     * @param  string  $type
52
     */
53
    protected function status($from, $to, $type): void
54
    {
55
        $this->components->task(sprintf('Copying %s [%s] to [%s]', $type,
56
            $this->normalizePath($from),
57
            $this->normalizePath($to)
58
        ));
59
    }
60
61
    protected function normalizePath(string $path): string
62
    {
63
        return ltrim(str_replace('\\', '/', Hyde::pathToRelative(realpath($path))), '/\\');
64
    }
65
}
66