Completed
Push — dev ( 38969c...e9d5f9 )
by Marc
13:15
created

Booter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 7
c 4
b 0
f 0
lcom 1
cbo 2
dl 0
loc 55
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 1
A beforeBooting() 0 13 4
A afterBooting() 0 16 2
1
<?php namespace Mascame\Artificer\Extension;
2
3
use Illuminate\Support\Str;
4
use Mascame\Extender\Booter\BooterInterface;
5
use Symfony\Component\CssSelector\XPath\Extension\AbstractExtension;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Mascame\Artificer\Extension\AbstractExtension.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use Symfony\Component\HttpFoundation\File\File;
7
8
class Booter extends \Mascame\Extender\Booter\Booter implements BooterInterface {
9
10
    /**
11
     * @var \Mascame\Artificer\Plugin\Manager|\Mascame\Artificer\Widget\Manager
12
     */
13
    protected $manager;
14
15
    public function boot($instance, $name)
16
    {
17
        $this->beforeBooting($instance, $name);
18
19
        parent::boot($instance, $name);
20
21
        $this->afterBooting($instance, $name);
22
    }
23
24
    /**
25
     * @param $instance
26
     * @param $name
27
     */
28
    public function beforeBooting($instance, $name) {
29
        $instance->namespace = $name;
30
31
        if (! $instance->version) {
32
            $instance->version = $this->manager->getVersion($instance->namespace);
33
        }
34
35
        if (! $instance->name) $instance->name = $name;
36
37
        if (! $instance->slug) $instance->slug = Str::slug($name);
38
39
        $this->manager->setSlug($instance->slug, $instance->namespace);
40
    }
41
    
42
    /**
43
     * @param $instance \Mascame\Artificer\Extension\AbstractExtension
44
     * @param $name
45
     */
46
    public function afterBooting($instance, $name) {
47
        if (! $this->manager->isInstalled($instance->namespace)) return;
48
49
        // Todo: add assets
50
//die('here!');
51
//        \Assets::config([
52
//            'group1' => [
53
//
54
//            ],
55
//        ]);
56
        $package = $instance->namespace . '/' . $instance->slug;
57
58
        \Assets::config([
59
60
        ])->add(["$package:bar.css", "$package:foo.js"]);
61
    }
62
}
63