OtpGeneratorServiceProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 7
eloc 25
c 2
b 0
f 2
dl 0
loc 80
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A register() 0 6 1
A registerCommands() 0 5 2
A registerDatabaseDriver() 0 13 1
A registerPublishing() 0 10 2
1
<?php
2
3
namespace DanielRobert\Otp;
4
5
use DanielRobert\Otp\Contracts\ClearableRepository;
6
use DanielRobert\Otp\Contracts\PrunableRepository;
7
use DanielRobert\Otp\Storage\DatabaseOtpsRepository;
8
use Illuminate\Support\ServiceProvider;
9
10
class OtpGeneratorServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap the application services.
14
     *
15
     * @return void
16
     */
17
18
     public const DB = __DIR__.'/../database/migrations';
19
     public const CONFIG = __DIR__.'/../config/otp-generator.php';
20
21
    public function boot(): void
22
    {
23
        $this->registerCommands();
24
        $this->registerPublishing();
25
    }
26
27
    /**
28
     * Register the package's publishable resources.
29
     *
30
     * @return void
31
     */
32
    private function registerPublishing()
33
    {
34
        if ($this->app->runningInConsole()) {
35
            $this->publishes([
36
                self::DB => database_path('migrations'),
37
            ], 'otp-migrations');
38
39
            $this->publishes([
40
                self::CONFIG => config_path('otp-generator.php'),
41
            ], 'otp-config');
42
        }
43
    }
44
45
    /**
46
     * Register the package's commands.
47
     *
48
     * @return void
49
     */
50
    protected function registerCommands()
51
    {
52
        if ($this->app->runningInConsole()) {
53
            $this->commands([
54
                Console\PublishCommand::class,
55
            ]);
56
        }
57
    }
58
59
    /**
60
     * Register any package services.
61
     *
62
     * @return void
63
     */
64
    public function register()
65
    {
66
        $this->mergeConfigFrom(
67
            self::CONFIG, 'otp-generator'
68
        );
69
        $this->app->alias(OtpGenerator::class, 'otp-generator');
70
    }
71
72
    /**
73
     * Register the package database storage driver.
74
     *
75
     * @return void
76
     */
77
    protected function registerDatabaseDriver()
78
    {
79
        $this->app->singleton(
80
            ClearableRepository::class, DatabaseOtpsRepository::class
81
        );
82
83
        $this->app->singleton(
84
            PrunableRepository::class, DatabaseOtpsRepository::class
85
        );
86
87
        $this->app->when(DatabaseOtpsRepository::class)
88
            ->needs('$connection')
89
            ->give(config('otp-generator.storage.database.connection'));
90
    }
91
}
92