Completed
Push — master ( b0b22f...359b9b )
by Benjamin
06:27
created

AbTestingServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

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