NoCaptchaServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 7 1
A boot() 0 6 2
A provides() 0 7 1
A registerNoCaptchaManager() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arcanedev\NoCaptcha;
6
7
use Arcanedev\NoCaptcha\Contracts\NoCaptcha as NoCaptchaContract;
8
use Arcanedev\NoCaptcha\Contracts\NoCaptchaManager as NoCaptchaManagerContract;
9
use Arcanedev\Support\Providers\PackageServiceProvider as ServiceProvider;
10
use Illuminate\Contracts\Foundation\Application;
11
use Illuminate\Contracts\Support\DeferrableProvider;
12
13
/**
14
 * Class     NoCaptchaServiceProvider
15
 *
16
 * @package  Arcanedev\NoCaptcha
17
 * @author   ARCANEDEV <[email protected]>
18
 */
19
class NoCaptchaServiceProvider extends ServiceProvider implements DeferrableProvider
20
{
21
    /* -----------------------------------------------------------------
22
     |  Properties
23
     | -----------------------------------------------------------------
24
     */
25
26
    /**
27
     * Package name.
28
     *
29
     * @var string
30
     */
31
    protected $package = 'no-captcha';
32
33
    /* -----------------------------------------------------------------
34
     |  Main Methods
35
     | -----------------------------------------------------------------
36
     */
37
38
    /**
39
     * Register the service provider.
40
     */
41 66
    public function register(): void
42
    {
43 66
        parent::register();
44
45 66
        $this->registerConfig();
46 66
        $this->registerNoCaptchaManager();
47 66
    }
48
49
    /**
50
     * Bootstrap the application events.
51
     */
52 66
    public function boot(): void
53
    {
54 66
        if ($this->app->runningInConsole()) {
55 66
            $this->publishConfig();
56
        }
57 66
    }
58
59
    /**
60
     * Get the services provided by the provider.
61
     *
62
     * @return array
63
     */
64 12
    public function provides(): array
65
    {
66
        return [
67 12
            NoCaptchaContract::class,
68
            NoCaptchaManagerContract::class,
69
        ];
70
    }
71
72
    /* -----------------------------------------------------------------
73
     |  Other Methods
74
     | -----------------------------------------------------------------
75
     */
76
77
    /**
78
     * Register noCaptcha manager & contract.
79
     */
80 66
    private function registerNoCaptchaManager(): void
81
    {
82 66
        $this->singleton(NoCaptchaManagerContract::class, NoCaptchaManager::class);
83
84
        $this->bind(NoCaptchaContract::class, function (Application $app) {
85
            /** @var  \Illuminate\Contracts\Config\Repository  $config */
86 30
            $config = $app['config'];
87
88 30
            return $app->make(NoCaptchaManagerContract::class)->version(
89 30
                $config->get('no-captcha.version')
90
            );
91 66
        });
92 66
    }
93
}
94