LaravelPretendServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 14 3
A register() 0 10 1
A isLumen() 0 4 1
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