LoadsmanServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 95.24%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 40
ccs 20
cts 21
cp 0.9524
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 23 3
A getConfigPath() 0 4 1
A boot() 0 5 1
1
<?php
2
3
namespace Loadsman\LaravelPlugin;
4
5
use Illuminate\Container\Container;
6
use Loadsman\LaravelPlugin\Modules\Framework\FrameworkServiceProvider;
7
use Loadsman\LaravelPlugin\Modules\Rule\RuleRepository;
8
use Loadsman\LaravelPlugin\Modules\Rule\RuleServiceProvider;
9
use Loadsman\LaravelPlugin\Providers\MacroServiceProvider;
10
use Loadsman\LaravelPlugin\Providers\RepositoryServiceProvider;
11
use Loadsman\LaravelPlugin\Providers\RouteServiceProvider;
12
use Illuminate\Routing\Router;
13
14
class LoadsmanServiceProvider extends \Illuminate\Support\ServiceProvider
15
{
16 3
    public function register()
17
    {
18 3
        $this->mergeConfigFrom($this->getConfigPath(), 'loadsman');
19
20 3
        if (! $this->app['config']['loadsman.enabled']) {
21
            return;
22
        }
23
24 3
        $this->app->register(MacroServiceProvider::class);
25 3
        $this->app->register(FrameworkServiceProvider::class);
26 3
        $this->app->register(RuleServiceProvider::class);
27
28 3
        $this->app->bind(RuleRepository::class, function (Container $app) {
29
30 3
            $routers = [];
31 3
            foreach ($app['config']['loadsman.routers'] as $routerName){
32 3
                $routers[] = $app->make($routerName);
33 2
            }
34
35 3
            return new RuleRepository($routers);
36 3
        });
37
38 3
    }
39
40
    /**
41
     * @return string
42
     */
43 3
    private function getConfigPath()
44
    {
45 3
        return realpath(__DIR__.'/../').'/config/loadsman.php';
46
    }
47
48 3
    public function boot()
49
    {
50 3
        $paths = [$this->getConfigPath() => config_path('loadsman.php')];
51 3
        $this->publishes($paths, 'config');
52 3
    }
53
}
54