AppServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 18 2
A register() 0 2 1
1
<?php
2
3
namespace App\Providers;
4
5
use Illuminate\Support\Facades\Validator;
6
use Illuminate\Support\ServiceProvider;
7
use Illuminate\Pagination\Paginator;
8
use Illuminate\Support\Facades\DB;
9
use Illuminate\Support\Facades\View;
10
11
class AppServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Register any application services.
15
     *
16
     * @return void
17
     */
18
    public function register()
19
    {
20
        //
21
    }
22
23
    /**
24
     * Bootstrap any application services.
25
     *
26
     * @return void
27
     */
28
    public function boot()
29
    {
30
        Paginator::useBootstrap();
31
        Validator::extend('isunique', function ($attribute, $value, $parameters, $validator) {
0 ignored issues
show
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

31
        Validator::extend('isunique', function ($attribute, $value, $parameters, /** @scrutinizer ignore-unused */ $validator) {

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

Loading history...
32
            $value = strtolower($value);
33
            $query = DB::table($parameters[0])->whereRaw("LOWER({$attribute}) = ?", [$value]);
34
35
            if (isset($parameters[1])) {
36
                $query->where($parameters[1], '!=', $parameters[2]);
37
            }
38
39
            return $query->count() === 0;
40
        });
41
        Validator::extend('exturl', function ($attribute, $value, $parameters, $validator) {
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

41
        Validator::extend('exturl', function ($attribute, $value, /** @scrutinizer ignore-unused */ $parameters, $validator) {

This check looks for 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 $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

41
        Validator::extend('exturl', function ($attribute, $value, $parameters, /** @scrutinizer ignore-unused */ $validator) {

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

Loading history...
42
            $allowed_schemes = ['http', 'https', 'mailto', 'tel'];
43
            return in_array(parse_url($value, PHP_URL_SCHEME), $allowed_schemes, true);
44
        });
45
        View::addNamespace('blocks', base_path('blocks'));
46
    }
47
}
48