AppServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 21 4
A register() 0 4 1
1
<?php
2
3
namespace LearnParty\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
use Validator;
7
use LearnParty\Category;
8
9
class AppServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap any application services.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        Validator::extend('youtube_url', 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...
19
20
            $urlParts = [
21
                'scheme',
22
                'host',
23
                'path',
24
                'query',
25
            ];
26
27
            if ($url = parse_url($value)) {
28
                if (count(array_diff($urlParts, array_keys($url))) == 0) {
29
                    return $url['host'] === 'youtube.com' || $url['host'] === 'www.youtube.com';
30
                }
31
            }
32
            return false;
33
        });
34
35
        view()->composer('layouts.side_nav', 'LearnParty\Http\Composers\SideNavComposer');
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...
36
    }
37
38
    /**
39
     * Register any application services.
40
     *
41
     * @return void
42
     */
43
    public function register()
44
    {
45
        //
46
    }
47
}
48