UninstallCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 26.32%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 70
ccs 5
cts 19
cp 0.2632
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A removeAdminUser() 0 3 1
A removeMigration() 0 11 3
A __construct() 0 6 1
A handle() 0 6 1
1
<?php
2
3
namespace Enomotodev\LaractiveAdmin\Console;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Composer;
7
use Illuminate\Filesystem\Filesystem;
8
9
class UninstallCommand extends Command
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $name = 'laractive-admin:uninstall';
15
16
    /**
17
     * @var string
18
     */
19
    protected $description = 'Uninstall LaractiveAdmin';
20
21
    /**
22
     * @var \Illuminate\Filesystem\Filesystem
23
     */
24
    protected $files;
25
26
    /**
27
     * @var \Illuminate\Support\Composer
28
     */
29
    protected $composer;
30
31
    /**
32
     * @param  \Illuminate\Filesystem\Filesystem  $files
33
     * @param  \Illuminate\Support\Composer  $composer
34
     * @return void
35
     */
36 11
    public function __construct(Filesystem $files, Composer $composer)
37
    {
38 11
        parent::__construct();
39
40 11
        $this->files = $files;
41 11
        $this->composer = $composer;
42 11
    }
43
44
    /**
45
     * @return void
46
     */
47
    public function handle()
48
    {
49
        $this->removeMigration();
50
        $this->removeAdminUser();
51
52
        $this->info('LaractiveAdmin uninstall successfully!');
53
    }
54
55
    /**
56
     * @return void
57
     */
58
    protected function removeMigration()
59
    {
60
        $migrations = [
61
            'create_admin_users_table',
62
            'create_laractive_admin_comments_table',
63
        ];
64
65
        $files = $this->files->files(database_path('migrations'));
66
        foreach ($files as $file) {
67
            if (in_array(substr($file->getFilename(), 18, -4), $migrations)) {
68
                unlink($file->getRealPath());
69
            }
70
        }
71
    }
72
73
    /**
74
     * @return void
75
     */
76
    protected function removeAdminUser()
77
    {
78
        $this->files->deleteDirectory(app_path('Admin'));
79
    }
80
}
81