Completed
Push — master ( c88560...7d3e5d )
by Benjamin
02:33
created

AbTestingServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 45

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 2.0011

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 14
cts 15
cp 0.9333
rs 9.2
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0011
1
<?php
2
3
namespace Ben182\AbTesting;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Blade;
7
use Illuminate\Support\ServiceProvider;
8
use Ben182\AbTesting\Commands\FlushCommand;
9
use Ben182\AbTesting\Commands\ReportCommand;
10
11
class AbTestingServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap the application services.
15
     */
16 45
    public function boot()
17
    {
18
        /*
19
         * Optional methods to load your package assets
20
         */
21
        // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-ab');
22
        // $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-ab');
23 45
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
24
        // $this->loadRoutesFrom(__DIR__.'/routes.php');
25
26 45
        if ($this->app->runningInConsole()) {
27 45
            $this->publishes([
28 45
                __DIR__.'/../config/config.php' => config_path('ab-testing.php'),
29 45
            ], 'config');
30
31
            // Publishing the views.
32
            /*$this->publishes([
33
                __DIR__.'/../resources/views' => resource_path('views/vendor/laravel-ab'),
34
            ], 'views');*/
35
36
            // Publishing assets.
37
            /*$this->publishes([
38
                __DIR__.'/../resources/assets' => public_path('vendor/laravel-ab'),
39
            ], 'assets');*/
40
41
            // Publishing the translation files.
42
            /*$this->publishes([
43
                __DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-ab'),
44
            ], 'lang');*/
45
46
            // Registering package commands.
47 45
            $this->commands([
48 45
                ReportCommand::class,
49
                FlushCommand::class,
50
            ]);
51
        }
52
53 15
        Request::macro('abExperiment', function () {
54 3
            return app(AbTesting::class)->getExperiment();
55 45
        });
56
57 15
        Blade::if('abExperiment', function ($experiment) {
58
            return app(AbTesting::class)->isExperiment($experiment);
59 45
        });
60 45
    }
61
62
    /**
63
     * Register the application services.
64
     */
65 45
    public function register()
66
    {
67
        // Automatically apply the package configuration
68 45
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'ab-testing');
69
70
        // Register the main class to use with the facade
71 15
        $this->app->singleton('ab-testing', function () {
72 45
            return new AbTesting;
73 45
        });
74 45
    }
75
}
76