Completed
Push — master ( a3d07b...f35753 )
by Arjay
14:10
created

bootAdministratorViewComposer()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 2
eloc 14
c 3
b 0
f 1
nc 1
nop 0
dl 0
loc 24
rs 8.9713
1
<?php
2
3
namespace Yajra\CMS\Providers;
4
5
use Illuminate\Contracts\View\View;
6
use Illuminate\Support\ServiceProvider;
7
use Illuminate\Support\Str;
8
use Yajra\Acl\Models\Permission;
9
use Yajra\CMS\Entities\Category;
10
use Yajra\CMS\Theme\Repository;
11
12
class ViewComposerServiceProvider extends ServiceProvider
13
{
14
    /**
15
     * Bootstrap the application services.
16
     *
17
     * @return void
18
     */
19
    public function boot()
20
    {
21
        $this->bootAdministratorViewComposer();
22
    }
23
24
    /**
25
     * Register administrator view composers.
26
     */
27
    protected function bootAdministratorViewComposer()
28
    {
29
        view()->composer('administrator.widgets.*', function (View $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...
30
            /** @var Repository $themes */
31
            $themes    = $this->app['themes'];
32
            $theme     = $themes->current();
33
            $positions = $theme->positions;
34
            $data      = [];
35
            foreach ($positions as $position) {
36
                $data[$position] = Str::title($position);
37
            }
38
39
            $view->with('widget_positions', $data);
40
            $view->with('theme', $theme);
41
        });
42
43
        view()->composer('administrator.articles.partials.form', function (View $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...
44
            $view->with('categories', Category::lists());
45
        });
46
47
        view()->composer(['administrator.partials.permissions'], function (View $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...
48
            $view->with('permissions', Permission::all());
49
        });
50
    }
51
52
    /**
53
     * Register the application services.
54
     *
55
     * @return void
56
     */
57
    public function register()
58
    {
59
        //
60
    }
61
}
62