AbTestingServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 43
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 23 2
A register() 0 10 1
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 51
    public function boot()
17
    {
18 51
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
19
20 51
        if ($this->app->runningInConsole()) {
21 51
            $this->publishes([
22 51
                __DIR__.'/../config/config.php' => config_path('ab-testing.php'),
23 51
            ], 'config');
24
25 51
            $this->commands([
26 51
                ReportCommand::class,
27
                ResetCommand::class,
28
            ]);
29
        }
30
31
        Request::macro('abExperiment', function () {
32 3
            return app(AbTesting::class)->getExperiment();
33 51
        });
34
35
        Blade::if('ab', function ($experiment) {
36 3
            return app(AbTesting::class)->isExperiment($experiment);
37 51
        });
38 51
    }
39
40
    /**
41
     * Register the application services.
42
     */
43 51
    public function register()
44
    {
45
        // Automatically apply the package configuration
46 51
        $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 51
            return new AbTesting;
51 51
        });
52 51
    }
53
}
54