Completed
Push — master ( 60f6bb...393bf4 )
by Sergi Tur
25:56
created

AdminLTEMenu::publishSpatieMenu()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Acacha\AdminLTETemplateLaravel\Console;
4
5
use Acacha\AdminLTETemplateLaravel\Exceptions\SpatieMenuAlreadyExists;
6
use Acacha\AdminLTETemplateLaravel\Facades\AdminLTE;
7
use Illuminate\Console\Command;
8
use Illuminate\Filesystem\Filesystem;
9
use Spatie\Menu\Laravel\MenuServiceProvider;
10
11
/**
12
 * Class AdminLTEMenu.
13
 */
14
class AdminLTEMenu extends Command
15
{
16
    use Installable;
17
18
    /**
19
     * The filesystem instance.
20
     *
21
     * @var \Illuminate\Filesystem\Filesystem
22
     */
23
    protected $files;
24
25
    /**
26
     * The name and signature of the console command.
27
     */
28
    protected $signature = 'adminlte-laravel:menu {--f|force : Force overwrite of files}';
29
30
    /**
31
     * The console command description.
32
     *
33
     * @var string
34
     */
35
    protected $description = 'Replaces sidebar view with a sidebar using spatie/laravel-menu menu';
36
37
    /**
38
     * Force overwrite of files.
39
     *
40
     * @var bool
41
     */
42
    protected $force = false;
43
44
    /**
45
     * Create a new command instance.
46
     *
47
     * @param \Illuminate\Filesystem\Filesystem $files
48
     *
49
     */
50
    public function __construct(Filesystem $files)
51
    {
52
        parent::__construct();
53
        $this->files = $files;
54
    }
55
56
    /**
57
     * Execute the console command.
58
     */
59
    public function handle()
60
    {
61
        $this->processOptions();
62
        $this->checkIfSpatieMenuAlreadyInstalled();
63
        $this->installSpatieMenu();
64
        $this->publishSpatieMenu();
65
        $this->publishSpatieMenuConfig();
66
    }
67
68
    /**
69
     * Check if spatie menu is already installed.
70
     *
71
     * @throws SpatieMenuAlreadyExists
72
     */
73
    protected function checkIfSpatieMenuAlreadyInstalled()
74
    {
75
        if ((app()->getProvider(MenuServiceProvider::class)) && ! $this->force) {
76
            throw new SpatieMenuAlreadyExists();
77
        }
78
        return;
79
    }
80
81
    /**
82
     * Install spatie/laravel-menu.
83
     */
84
    protected function installSpatieMenu()
85
    {
86
        passthru('llum package laravel-menu');
87
    }
88
89
    /**
90
     * Process options before running command.
91
     */
92
    protected function processOptions()
93
    {
94
        $this->force = $this->option('force');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->option('force') of type string or array is incompatible with the declared type boolean of property $force.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
95
    }
96
97
    /**
98
     * Publish sidebar with spatie menu
99
     */
100
    protected function publishSpatieMenu()
101
    {
102
        $this->install(AdminLTE::spatieMenu());
103
    }
104
105
    /**
106
     * Publish spatie menu config
107
     */
108
    protected function publishSpatieMenuConfig()
109
    {
110
        $this->install(AdminLTE::menu());
111
    }
112
}
113