LaravelPretendServiceProvider::boot()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.7998
c 0
b 0
f 0
cc 3
nc 4
nop 0
crap 3
1
<?php declare(strict_types=1);
2
3
namespace Scif\LaravelPretend;
4
5
use Illuminate\Contracts\Auth\UserProvider;
6
use Illuminate\Support\ServiceProvider;
7
use Scif\LaravelPretend\Service\Impersonator;
8
9
class LaravelPretendServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap the application services.
13
     *
14
     * @return void
15
     */
16 7
    public function boot()
17
    {
18 7
        $configPath = __DIR__ . '/../config/pretend.php';
19
20 7
        if ( ! $this->isLumen()) {
21 7
            $this->publishes([$configPath => config_path('pretend.php')], 'config');
22
        }
23
24 7
        $this->mergeConfigFrom($configPath, 'pretend');
25
26 7
        if (!$this->app->bound('impersonator')) {
27 7
            $this->app->bind('impersonator', Impersonator::class);
28
        }
29 7
    }
30
31
    /**
32
     * Register the application services.
33
     *
34
     * @return void
35
     */
36 7
    public function register()
37
    {
38 7
        $this->app->when(Impersonator::class)
39 7
          ->needs(UserProvider::class)
40 7
          ->give(function (): UserProvider {
41 7
              return \Auth::getProvider();
42 7
          });
43
44 7
        $this->app->singleton(Impersonator::class, Impersonator::class);
45 7
    }
46
47
    /**
48
     * Check if we are running Lumen or not.
49
     *
50
     * @return bool
51
     */
52 7
    protected function isLumen(): bool
53
    {
54 7
        return strpos($this->app->version(), 'Lumen') !== false;
55
    }
56
}
57