Completed
Push — develop ( f77fd9...d910ff )
by Abdelrahman
10:08
created

AuthServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Auth\Providers;
6
7
use Illuminate\Routing\Router;
8
use Illuminate\Support\ServiceProvider;
9
use Illuminate\Support\Facades\Validator;
10
use Rinvex\Auth\Console\Commands\PublishCommand;
11
use Rinvex\Auth\Services\PasswordResetBrokerManager;
12
use Rinvex\Auth\Services\EmailVerificationBrokerManager;
13
14
class AuthServiceProvider extends ServiceProvider
15
{
16
    /**
17
     * The commands to be registered.
18
     *
19
     * @var array
20
     */
21
    protected $commands = [
22
        PublishCommand::class => 'command.rinvex.auth.publish',
23
    ];
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function register()
29
    {
30
        // Merge config
31
        $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.auth');
32
33
        // Register console commands
34
        ! $this->app->runningInConsole() || $this->registerCommands();
35
36
        // Register the password reset broker manager
37
        $this->app->singleton('auth.password', function ($app) {
38
            return new PasswordResetBrokerManager($app);
39
        });
40
41
        // Register the verification broker manager
42
        $this->app->singleton('rinvex.auth.emailverification', function ($app) {
43
            return new EmailVerificationBrokerManager($app);
44
        });
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function boot(Router $router)
0 ignored issues
show
Unused Code introduced by
The parameter $router is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
    {
52
        // Add country validation rule
53
        Validator::extend('country', function ($attribute, $value) {
54
            return in_array($value, array_keys(countries()));
55
        }, 'Country MUST be valid!');
56
57
        // Add langauge validation rule
58
        Validator::extend('language', function ($attribute, $value) {
59
            return in_array($value, array_keys(languages()));
60
        }, 'Language MUST be valid!');
61
62
        // Publish resources
63
        ! $this->app->runningInConsole() || $this->publishes([realpath(__DIR__.'/../../config/config.php') => config_path('rinvex.auth.php')], 'rinvex-auth-config');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 165 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
64
    }
65
66
    /**
67
     * Register console commands.
68
     *
69
     * @return void
70
     */
71
    protected function registerCommands(): void
72
    {
73
        // Register artisan commands
74
        foreach ($this->commands as $key => $value) {
75
            $this->app->singleton($value, $key);
76
        }
77
78
        $this->commands(array_values($this->commands));
79
    }
80
}
81