EcommerceServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 23
dl 0
loc 56
ccs 28
cts 28
cp 1
rs 10
c 2
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A mustLoadRoute() 0 3 1
A register() 0 4 1
A routeConfiguration() 0 5 1
A boot() 0 23 3
1
<?php
2
3
namespace Lenius\LaravelEcommerce;
4
5
use Illuminate\Support\Facades\Route;
6
use Illuminate\Support\ServiceProvider;
7
use Lenius\LaravelEcommerce\Identifier\LaravelCookie;
8
use Lenius\LaravelEcommerce\Storage\LaravelSession;
9
10
class EcommerceServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap the application services.
14
     *
15
     * @return void
16
     */
17 4
    public function boot(): void
18
    {
19 4
        if ($this->app->runningInConsole()) {
20 4
            $this->publishes([
21 4
                __DIR__.'/../config/ecommerce.php' => config_path('ecommerce.php'),
22 4
            ], 'config');
23
24 4
            $this->publishes([
25 4
                __DIR__.'/../resources/views' => resource_path('views/vendor/ecommerce'),
26 4
            ], 'views');
27
28 4
            $this->publishes([
29 4
                __DIR__.'/../resources/lang' => resource_path('lang/vendor/ecommerce'),
30 4
            ], 'lang');
31
        };
32
33 4
        $this->loadMigrationsFrom(__DIR__.'/../databases/migrations');
34 4
        $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'ecommerce');
35 4
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'ecommerce');
36
37 4
        if ($this->mustLoadRoute()) {
38 4
            Route::group($this->routeConfiguration(), function () {
39 4
                $this->loadRoutesFrom(__DIR__.'/routes.php');
40 4
            });
41
        }
42
    }
43
44 4
    protected function mustLoadRoute(): bool
45
    {
46 4
        return ! config('ecommerce.disable_default_route', false);
47
    }
48
49 4
    protected function routeConfiguration(): array
50
    {
51 4
        return [
52 4
            'prefix'     => config('ecommerce.prefix', 'ecommerce'),
53 4
            'middleware' => config('ecommerce.middleware', 'web'),
54 4
        ];
55
    }
56
57
    /**
58
     * Register the application services.
59
     *
60
     * @return void
61
     */
62 4
    public function register(): void
63
    {
64 4
        $this->app->singleton('cart', function () {
65 4
            return new Cart(new LaravelSession(), new LaravelCookie(), resolve('events'));
66 4
        });
67
    }
68
}
69