Completed
Pull Request — master (#24)
by Brandon
01:59
created

AppServiceProvider::boot()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.1165

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 19
ccs 9
cts 13
cp 0.6923
rs 9.4285
cc 2
eloc 9
nc 1
nop 0
crap 2.1165
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 5
    }
35
36
    /**
37
     * Register any application services.
38
     *
39
     * @return void
40
     */
41 5
    public function register()
42
    {
43
        //
44 5
    }
45
}
46