LaravelTwitterHandleValidationServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 27 3
A register() 0 10 1
1
<?php
2
3
namespace BrunoFernandes\LaravelTwitterHandleValidation;
4
5
use Illuminate\Support\Facades\Validator;
6
use Illuminate\Support\ServiceProvider;
7
8
class LaravelTwitterHandleValidationServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     */
13
    public function boot()
14
    {
15
        Validator::extend('twitter_handle', '\BrunoFernandes\LaravelTwitterHandleValidation\TwitterHandleValidator@validate');
16
        Validator::replacer( 'twitter_handle', function ($message, $attribute, $rule, $parameters) {
0 ignored issues
show
Unused Code introduced by
The parameter $rule 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...
Unused Code introduced by
The parameter $parameters 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...
17
            if ($message == 'validation.twitter_handle') {
18
                return str_replace(':attribute', $attribute, config('laravel-twitter-handle-validation.validation'));
19
            }
20
21
            return $message;
22
        });
23
24
        /*
25
         * Optional methods to load your package assets
26
         */
27
        // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-twitter-handle-validation');
28
29
        if ($this->app->runningInConsole()) {
30
            $this->publishes([
31
                __DIR__.'/../config/laravel-twitter-handle-validation.php' => config_path('laravel-twitter-handle-validation.php'),
32
            ], 'config');
33
34
            // Publishing the translation files.
35
            /*$this->publishes([
36
                __DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-twitter-handle-validation'),
37
            ], 'lang');*/
38
        }
39
    }
40
41
    /**
42
     * Register the application services.
43
     */
44
    public function register()
45
    {
46
        // Automatically apply the package configuration
47
        $this->mergeConfigFrom(__DIR__.'/../config/laravel-twitter-handle-validation.php', 'laravel-twitter-handle-validation');
48
49
        // Register the main class to use with the facade
50
        $this->app->singleton('laravel-twitter-handle-validation', function () {
51
            return resolve(LaravelTwitterHandleValidation::class);
52
        });
53
    }
54
}
55