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

PublishAdminLTE   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 124
Duplicated Lines 8.87 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 15
c 0
b 0
f 0
lcom 1
cbo 1
dl 11
loc 124
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 11 11 1
A publishHomeController() 0 4 1
A changeRegisterController() 0 4 1
A publishPublicAssets() 0 4 1
A publishViews() 0 4 1
A publishResourceAssets() 0 4 1
A publishTests() 0 4 1
A publishLanguages() 0 4 1
A publishGravatar() 0 4 1
A install() 0 10 4
A confirmOverwrite() 0 7 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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