Completed
Push — master ( f10077...eddc4f )
by Elf
03:19 queued 02:07
created

AppsServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 69
ccs 25
cts 25
cp 1
rs 10
wmc 7
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 2
A publishAssets() 0 6 1
A register() 0 9 1
A setupAssets() 0 8 2
A macroUrlGenerator() 0 6 1
1
<?php
2
3
namespace ElfSundae\Laravel\Apps;
4
5
use Illuminate\Support\ServiceProvider;
6
use Laravel\Lumen\Application as LumenApplication;
7
8
class AppsServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the service provider.
12
     *
13
     * @return void
14
     */
15 2
    public function boot()
16
    {
17 2
        $this->macroUrlGenerator();
18
19 2
        if ($this->app->runningInConsole()) {
20 2
            $this->publishAssets();
21
        }
22 2
    }
23
24
    /**
25
     * Register macros for UrlGenerator.
26
     *
27
     * @return void
28
     */
29 2
    protected function macroUrlGenerator()
30
    {
31
        $this->app['url']->macro('getRootControllerNamespace', function () {
32 1
            return $this->rootNamespace;
0 ignored issues
show
Bug introduced by
The property rootNamespace does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33 2
        });
34 2
    }
35
36
    /**
37
     * Publish assets from package.
38
     *
39
     * @return void
40
     */
41 2
    protected function publishAssets()
42
    {
43 2
        $this->publishes([
44 2
            __DIR__.'/../config/apps.php' => base_path('config/apps.php'),
45 2
        ], 'laravel-apps');
46 2
    }
47
48
    /**
49
     * Register the service provider.
50
     *
51
     * @return void
52
     */
53 2
    public function register()
54
    {
55 2
        $this->setupAssets();
56
57 2
        $this->app->singleton('apps', function ($app) {
58 1
            return new Apps($app);
59 2
        });
60 2
        $this->app->alias('apps', Apps::class);
61 2
    }
62
63
    /**
64
     * Setup package assets.
65
     *
66
     * @return void
67
     */
68 2
    protected function setupAssets()
69
    {
70 2
        if ($this->app instanceof LumenApplication) {
71
            $this->app->configure('apps'); // @codeCoverageIgnore
72
        }
73
74 2
        $this->mergeConfigFrom(__DIR__.'/../config/apps.php', 'apps');
75 2
    }
76
}
77