ValidServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 32
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A boot() 0 26 3
1
<?php
2
3
namespace PerfectOblivion\Valid;
4
5
use Illuminate\Routing\Redirector;
6
use Illuminate\Support\ServiceProvider;
7
use PerfectOblivion\Valid\Commands\CustomRuleMakeCommand;
8
use Illuminate\Contracts\Validation\ValidatesWhenResolved;
9
use PerfectOblivion\Valid\Commands\FormRequestMakeCommand;
10
use PerfectOblivion\Valid\ValidationService\ValidationService;
11
use PerfectOblivion\Valid\Commands\ValidationServiceMakeCommand;
12
13
class ValidServiceProvider extends ServiceProvider
14
{
15
    /**
16
     * Bootstrap the application services.
17
     */
18
    public function boot()
19
    {
20
        if ($this->app->runningInConsole()) {
21
            $this->publishes([
22
                __DIR__.'/../config/valid.php' => config_path('valid.php'),
23
            ]);
24
        }
25
26
        $this->mergeConfigFrom(__DIR__.'/../config/valid.php', 'valid');
27
28
        $this->app->resolving(ValidatesWhenResolved::class, function ($resolved) {
29
            if (method_exists($resolved, 'prepareCustomRules')) {
30
                $resolved->prepareCustomRules();
31
            }
32
        });
33
34
        $this->app->resolving(ValidationService::class, function ($resolved, $app) {
35
            $resolved->setContainer($app)->setRedirector($app->make(Redirector::class));
36
        });
37
38
        $this->commands([
39
            FormRequestMakeCommand::class,
40
            CustomRuleMakeCommand::class,
41
            ValidationServiceMakeCommand::class,
42
        ]);
43
    }
44
}
45