Completed
Push — master ( 87f5e0...117349 )
by Benjamin
05:50
created

AbTestingServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 0
cts 13
cp 0
rs 9.552
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
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
    public function boot()
17
    {
18
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
19
20
        if ($this->app->runningInConsole()) {
21
            $this->publishes([
22
                __DIR__.'/../config/config.php' => config_path('ab-testing.php'),
23
            ], 'config');
24
25
            $this->commands([
26
                ReportCommand::class,
27
                FlushCommand::class,
28
            ]);
29
        }
30
31
        Request::macro('abExperiment', function () {
32
            return app(AbTesting::class)->getExperiment();
33
        });
34
35
        Blade::if('abExperiment', function ($experiment) {
36
            return app(AbTesting::class)->isExperiment($experiment);
37
        });
38
    }
39
40
    /**
41
     * Register the application services.
42
     */
43
    public function register()
44
    {
45
        // Automatically apply the package configuration
46
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'ab-testing');
47
48
        // Register the main class to use with the facade
49
        $this->app->singleton('ab-testing', function () {
50
            return new AbTesting;
51
        });
52
    }
53
}
54