PasswordServiceProvider::boot()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 18
rs 9.9332
cc 3
nc 3
nop 0
1
<?php
2
3
namespace Benjafield\LaravelPasswordManager;
4
5
use Benjafield\LaravelPasswordManager\Commands\GeneratePasswordKeyCommand;
6
use Illuminate\Support\ServiceProvider;
7
8
class PasswordServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Register package services.
12
     *
13
     * @return void
14
     */
15
    public function register()
16
    {
17
        $this->mergeConfigFrom(__DIR__ . '/../config/passwords.php', 'passwords');
18
19
        $this->app->bind('passwords', fn () => new PasswordManager);
20
    }
21
22
    /**
23
     * Bootstrap package services.
24
     *
25
     * @return void
26
     */
27
    public function boot()
28
    {
29
        if ($this->app->runningInConsole()) {
30
            // Publish the config file.
31
            $this->publishes([
32
                __DIR__ . '/../config/passwords.php' => config_path('passwords.php'),
33
            ], 'config');
34
35
            // Publish the database migrations
36
            if (! class_exists('CreatePasswordsTable')) {
37
                $this->publishes([
38
                    __DIR__ . '/../database/migrations/create_passwords_table.php.stub' => database_path('migrations/' . date('Y_m_d_His', time()) . '_create_passwords_table.php'),
39
                ], 'migrations');
40
            }
41
42
            // Register console commands.
43
            $this->commands([
44
                GeneratePasswordKeyCommand::class,
45
            ]);
46
        }
47
    }
48
}