Completed
Push — master ( 1680b9...7d3d6e )
by Mohamed
15s queued 11s
created

DefaultRole::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Microboard\Widgets;
4
5
use Microboard\Foundations\Widget;
6
use Microboard\Models\Role;
7
8 View Code Duplication
class DefaultRole extends Widget
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    /**
11
     * The configuration array.
12
     *
13
     * @var array
14
     */
15
    protected $config = [
16
        'background' => 'bg-white',
17
        'icon-background' => 'primary',
18
        'text' => 'dark'
19
    ];
20
21
    /**
22
     * Treat this method as a controller action.
23
     * Return view() or other content to display.
24
     */
25
    public function run()
26
    {
27
        return view('microboard::state', [
28
            'config' => $this->config,
29
            'title' => trans('microboard::pages.widgets.default-role.title'),
30
            'info' => trans('microboard::pages.widgets.default-role.info'),
31
            'icon' => 'ni ni-key-25',
32
            'count' => Role::where('name', config('microboard.roles.default', 'admin'))->first()->display_name
33
        ]);
34
    }
35
36
    /**
37
     * Determine if the widget should be displayed.
38
     *
39
     * @return bool
40
     */
41
    public function shouldBeDisplayed()
42
    {
43
        return auth()->user()->can('viewAny', new Role);
0 ignored issues
show
Bug introduced by
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

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
    }
45
}
46