Completed
Push — master ( d544c0...506b6d )
by Sergi Tur
02:41
created

PublishAdminLTE::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 11
loc 11
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace Acacha\AdminLTETemplateLaravel\Console;
4
5
use Illuminate\Console\Command;
6
7
/**
8
 * Class PublishAdminLTE.
9
 */
10
class PublishAdminLTE extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     */
15
    protected $signature = 'adminlte-laravel:publish';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Publish Acacha AdminLTE Template files into laravel project';
23
24
    /**
25
     * Execute the console command.
26
     *
27
     */
28 View Code Duplication
    public function handle()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        $this->publishHomeController();
31
        $this->changeRegisterController();
32
        $this->publishPublicAssets();
33
        $this->publishViews();
34
        $this->publishResourceAssets();
35
        $this->publishTests();
36
        $this->publishLanguages();
37
        $this->publishGravatar();
38
    }
39
40
    /**
41
     * Install Home Controller.
42
     */
43
    private function publishHomeController()
44
    {
45
        $this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::homeController());
46
    }
47
48
    /**
49
     * Install Auth controller.
50
     */
51
    private function changeRegisterController()
52
    {
53
        $this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::registerController());
54
    }
55
56
    /**
57
     * Install public assets.
58
     */
59
    private function publishPublicAssets()
60
    {
61
        $this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::publicAssets());
62
    }
63
64
    /**
65
     * Install views.
66
     */
67
    private function publishViews()
68
    {
69
        $this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::views());
70
    }
71
72
    /**
73
     * Install resource assets.
74
     */
75
    private function publishResourceAssets()
76
    {
77
        $this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::resourceAssets());
78
    }
79
80
    /**
81
     * Install resource assets.
82
     */
83
    private function publishTests()
84
    {
85
        $this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::tests());
86
    }
87
88
    /**
89
     * Install language assets.
90
     */
91
    private function publishLanguages()
92
    {
93
        $this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::languages());
94
    }
95
96
    /**
97
     * Install gravatar config file.
98
     */
99
    private function publishGravatar()
100
    {
101
        $this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::gravatar());
102
    }
103
104
    /**
105
     * Install files from array.
106
     *
107
     * @param $files
108
     */
109
    private function install($files)
110
    {
111
        foreach ($files as $fileSrc => $fileDst) {
112
            if (file_exists($fileDst) && !$this->confirmOverwrite(basename($fileDst))) {
113
                return;
114
            }
115
            copy($fileSrc, $fileDst);
116
            $this->info('Copied file ' . $fileSrc . ' to ' . $fileDst );
117
        }
118
    }
119
120
    /**
121
     * @param $fileName
122
     * @param string $prompt
123
     *
124
     * @return bool
125
     */
126
    protected function confirmOverwrite($fileName, $prompt = '')
127
    {
128
        $prompt = (empty($prompt))
129
            ? $fileName.' already exists. Do you want to overwrite it? [y|N]'
130
            : $prompt;
131
        return $this->confirm($prompt, false);
132
    }
133
}
134