Completed
Push — dev ( 8e4a13...e9dbc4 )
by Marc
02:06
created

ExtensionController::getType()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 3
eloc 3
nc 3
nop 0
1
<?php namespace Mascame\Artificer\Http\Controllers;
2
3
use App;
4
use Illuminate\Support\Str;
5
use Mascame\Arrayer\Builder;
6
use Redirect;
7
use View;
8
9
class ExtensionController extends BaseController
10
{
11
    protected $type;
12
    
13
    protected function getManager() {
14
        if ($this->getType() == 'plugins') {
15
            return App::make('ArtificerPluginManager');
16
        }
17
18
        return App::make('ArtificerWidgetManager');
19
    }
20
    
21
    protected function getType() {
22
        if ($this->type) return $this->type;
23
        
24
        return Str::startsWith(\Route::currentRouteName(), 'admin.plugins') ? 'plugins' : 'widgets';   
25
    }
26
    
27
    public function extensions()
28
    {
29
        return View::make($this->getView('extensions'))
30
            ->with('type', $this->getType())
31
            ->with('extensions', $this->getManager()->getAll());
32
    }
33
34
    public function install($plugin)
35
    {
36
        $plugin = $this->getExtensionSlug($plugin);
37
38
        $this->getManager()->installer()->install($plugin);
39
40
        return \Redirect::back();
0 ignored issues
show
Bug introduced by
The method back() does not seem to exist on object<redirect>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
    }
42
43
    public function uninstall($plugin)
44
    {
45
        $plugin = $this->getExtensionSlug($plugin);
46
47
        $this->getManager()->installer()->uninstall($plugin);
48
49
        return \Redirect::back();
0 ignored issues
show
Bug introduced by
The method back() does not seem to exist on object<redirect>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
    }
51
52
    protected function getExtensionSlug($plugin) {
53
        return $this->getManager()->getFromSlug($plugin)->namespace;
54
    }
55
56
}