EcommerceServiceProvider::boot()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 16
c 2
b 0
f 0
nc 4
nop 0
dl 0
loc 23
ccs 17
cts 17
cp 1
crap 3
rs 9.7333
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