Completed
Pull Request — master (#113)
by
unknown
02:28
created

AppServiceProvider::boot()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 91
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 41
CRAP Score 2.141

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 91
ccs 41
cts 61
cp 0.6721
rs 8.518
cc 2
eloc 41
nc 1
nop 0
crap 2.141

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
use Illuminate\Support\Facades\Schema;
7
use Illuminate\Support\Facades\Validator;
8
9
class AppServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap any application services.
13
     *
14
     * @return void
15
     */
16 5
    public function boot()
17
    {
18
        // Fixes incompatibility with MySQL < 5.7.7
19 5
        Schema::defaultStringLength(191);
20
21
        // Create {{ $view_name }} provider in blade templates
22 5
        view()->composer('*', function($view) {
0 ignored issues
show
Bug introduced by
The method composer does only exist in Illuminate\Contracts\View\Factory, but not in Illuminate\View\View.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
23
            $view_name = str_replace('.', '-', $view->getName());
24
            view()->share('view_name', $view_name);
0 ignored issues
show
Bug introduced by
The method share does only exist in Illuminate\Contracts\View\Factory, but not in Illuminate\View\View.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
25 5
        });
26
27 5
        Validator::extend('phone', function($attribute, $value, $parameters, $validator) {
0 ignored issues
show
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...
Unused Code introduced by
The parameter $validator 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...
28
            return preg_match('%^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\ \\\/]?)?((?:\(?\d{1,}\)?[\-\.\ \\\/]?){0,})(?:[\-\.\ \\\/]?(?:#|ext\.?|extension|x)[\-\.\ \\\/]?(\d+))?$%i', $value) && strlen($value) >= 10;
29 5
        });
30
31 5
        Validator::replacer('phone', 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...
32
            return str_replace(':attribute', $attribute, ':attribute is invalid phone number');
33 5
        });
34
    
35
        //Validator rule for names
36 5
        Validator::extend('name', function($attribute, $value, $parameters, $validator) {
0 ignored issues
show
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...
Unused Code introduced by
The parameter $validator 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...
37
            return preg_match('#(^[[:alnum:]])([\w\-\.\' ]*)([\w\-\.\']$)#', $value);
38 5
        });
39
    
40 5
        Validator::replacer('name', 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...
41
            return str_replace(':attribute', $attribute, ':attribute is invalid you can only use letters, numbers, underscores, dashes, spaces, periods and it must start with a letter or number');
42 5
        });
43
    
44
        //Validator rule for user full names
45 5
        Validator::extend('full_name', function($attribute, $value, $parameters, $validator) {
0 ignored issues
show
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...
Unused Code introduced by
The parameter $validator 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...
46
            return preg_match('#(^[[:alpha:]])([[:alpha:]\_\-\. ]*)([[:alpha:]\_\-\.]$)#', $value);
47 5
        });
48
    
49 5
        Validator::replacer('full_name', 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...
50
            return str_replace(':attribute', $attribute, ':attribute is invalid you can only use letters, underscores, dashes, spaces, periods and it must start with a letter');
51 5
        });
52
    
53
        //Validator rule for values
54 5
        Validator::extend('value_string', function($attribute, $value, $parameters, $validator) {
0 ignored issues
show
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...
Unused Code introduced by
The parameter $validator 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...
55
            return preg_match('#(^[[:alnum:]\+\-])([\w\+\-\.\'\, ]*$)#', $value);
56 5
        });
57
    
58 5
        Validator::replacer('value_string', 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...
59
            return str_replace(':attribute', $attribute, ':attribute is invalid you can only use alphanumerics spaces +-_.\', and it must start with a alphanumeric or a plus or minus');
60 5
        });
61
    
62
        //Validator rule for types
63 5
        Validator::extend('type_name', function($attribute, $value, $parameters, $validator) {
0 ignored issues
show
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...
Unused Code introduced by
The parameter $validator 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...
64
            return preg_match('#(^[[:alpha:]\_])([\w]*$)#', $value);
65 5
        });
66
    
67 5
        Validator::replacer('type_name', 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...
68
            return str_replace(':attribute', $attribute, ':attribute is invalid you can only use alphanumerics, underscores and it must start with a letter or underscore');
69 5
        });
70
    
71
        //Validator rule for error messages
72 5
        Validator::extend('error_string', function($attribute, $value, $parameters, $validator) {
0 ignored issues
show
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...
Unused Code introduced by
The parameter $validator 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...
73
            return preg_match('#(^[\w])([\w\-\.\'\, ]*$)#', $value);
74 5
        });
75
    
76 5
        Validator::replacer('error_string', 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...
77
            return str_replace(':attribute', $attribute, ':attribute is invalid you can only use alphanumerics spaces _.\', and it must start with a alphanumeric or underscore');
78 5
        });
79
    
80
        //Validator rule for mac addresses
81 5
        Validator::extend('mac', function($attribute, $value, $parameters, $validator) {
0 ignored issues
show
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...
Unused Code introduced by
The parameter $validator 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...
82
            return preg_match('#^(([[:xdigit:]]{2}){6})$#', $value);
83 5
        });
84
    
85 5
        Validator::replacer('mac', 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...
86
            return str_replace(':attribute', $attribute, ':attribute is invalid you must provide a valid mac address like 000000000000');
87 5
        });
88
    
89
        //Validator rule for versions
90 5
        Validator::extend('version', function($attribute, $value, $parameters, $validator) {
0 ignored issues
show
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...
Unused Code introduced by
The parameter $validator 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...
91
            return preg_match('#(^[0-9])(([\+\-\.][[:alnum:]]+)*$)#', $value);
92 5
        });
93
    
94 5
        Validator::replacer('version', 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...
95
            return str_replace(':attribute', $attribute, ':attribute is invalid you can only use alphanumerics +-. and it must start with a number and end with an alphanumeric');
96 5
        });
97
    
98
        //Validator rule for uuid
99 5
        Validator::extend('uuid', function($attribute, $value, $parameters, $validator) {
0 ignored issues
show
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...
Unused Code introduced by
The parameter $validator 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...
100
            return preg_match('#^([[:xdigit:]]{8})(-[[:xdigit:]]{4}){3}(-[[:xdigit:]]{12})$#', $value);
101 5
        });
102
    
103 5
        Validator::replacer('uuid', 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...
104
            return str_replace(':attribute', $attribute, ':attribute is invalid you must provide five groups of hexadecimals in the form 8-4-4-4-12');
105 5
        });
106 5
    }
107
108
    /**
109
     * Register any application services.
110
     *
111
     * @return void
112
     */
113 5
    public function register()
114
    {
115
        //
116 5
    }
117
}
118