Completed
Push — master ( a4261d...fc5e52 )
by John
14s
created

Uninstall   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 52
rs 10
c 3
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A create() 0 13 4
A handle() 0 6 2
1
<?php
2
3
namespace App\Console\Commands\Babel;
4
5
use Illuminate\Console\Command;
6
use Exception;
7
8
class Uninstall extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'babel:uninstall {extension : The package name of the extension}';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Uninstall a given Babel Extension to NOJ';
23
24
    /**
25
     * Create a new command instance.
26
     *
27
     * @return void
28
     */
29
    public function __construct()
30
    {
31
        parent::__construct();
32
    }
33
34
    /**
35
     * Execute the console command.
36
     *
37
     * @return mixed
38
     */
39
    public function handle()
40
    {
41
        $extension = $this->argument('extension');
42
        $submitter=self::create($extension,$this);
43
        if(!is_null($submitter)) $submitter->uninstall();
44
        else throw new Exception("Uninstaller Not Provided");
45
    }
46
47
    public static function create($oj,$class) {
48
        $installerProvider="Installer";
49
        try {
50
            $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$oj/babel.json")), true);
51
            $installerProvider=$BabelConfig["provider"]["installer"];
52
        } catch(ErrorException $e) {
0 ignored issues
show
Bug introduced by
The type App\Console\Commands\Babel\ErrorException was not found. Did you mean ErrorException? If so, make sure to prefix the type with \.
Loading history...
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
53
        } catch(Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
54
        }
55
        $className = "App\\Babel\\Extension\\$oj\\$installerProvider";
56
        if(class_exists($className)) {
57
            return new $className($class);
58
        } else {
59
            return null;
60
        }
61
    }
62
}
63