Passed
Push — master ( 051f8c...0effca )
by Daniel
02:41
created

OtpGeneratorServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 98
rs 10
c 0
b 0
f 0
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A register() 0 6 1
A registerCommands() 0 6 2
A registerDatabaseDriver() 0 17 1
A registerPublishing() 0 10 2
A registerMigrations() 0 4 2
1
<?php
2
3
namespace DanielRobert\Otp;
4
5
use DanielRobert\Otp\Contracts\ClearableRepository;
6
use DanielRobert\Otp\Contracts\OtpRepository;
0 ignored issues
show
Bug introduced by
The type DanielRobert\Otp\Contracts\OtpRepository was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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