Completed
Push — dev ( 9ff19d...9155f2 )
by Marc
03:27
created

Booter   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 8
Bugs 0 Features 1
Metric Value
wmc 10
c 8
b 0
f 1
lcom 1
cbo 2
dl 0
loc 54
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 1
B beforeBooting() 0 15 6
A afterBooting() 0 5 2
A addAssets() 0 4 1
1
<?php namespace Mascame\Artificer\Extension;
2
3
use Illuminate\Support\Str;
4
use Mascame\Artificer\Artificer;
5
use Mascame\Extender\Booter\BooterInterface;
6
7
class Booter extends \Mascame\Extender\Booter\Booter implements BooterInterface {
8
9
    /**
10
     * @var \Mascame\Artificer\Plugin\Manager|\Mascame\Artificer\Widget\Manager
11
     */
12
    protected $manager;
13
14
    public function boot($instance, $name)
15
    {
16
        $this->beforeBooting($instance, $name);
17
18
        parent::boot($instance, $name);
19
20
        $this->afterBooting($instance, $name);
21
    }
22
23
    /**
24
     * @param $instance
25
     * @param $name
26
     */
27
    protected function beforeBooting($instance, $name) {
28
        if (! $instance->namespace) $instance->namespace = $name;
29
        if (! $instance->name) $instance->name = $name;
30
        if (property_exists($instance, 'assetsPath')) {
31
            if (! $instance->assetsPath) $instance->assetsPath = 'packages/' . $instance->package . '/';
32
        }
33
34
        if (! $instance->slug) {
35
            // For slug readability
36
            $name = str_replace('\\', '-', $name);
37
            $instance->slug = Str::slug($name);
38
        }
39
40
        $this->manager->setSlug($instance->slug, $instance->namespace);
41
    }
42
    
43
    /**
44
     * @param $instance \Mascame\Artificer\Extension\AbstractExtension
45
     * @param $name
46
     */
47
    protected function afterBooting($instance, $name) {
48
        if (! $this->manager->isInstalled($instance->namespace)) return;
49
50
        $this->addAssets($instance);
51
    }
52
53
    /**
54
     * @param $instance
55
     */
56
    protected function addAssets($instance) {
0 ignored issues
show
Unused Code introduced by
The parameter $instance is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57
        // Todo: only add assets by default if its a plugin (widgets will load only when necessary)
58
//        $instance->assets(Artificer::assetManager());
59
    }
60
}
61