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

Uninstall::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 10
c 1
b 0
f 0
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