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

PermissionsCount::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
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\Permission;
7
use Microboard\Models\Role;
8
9
class PermissionsCount extends Widget
10
{
11
    /**
12
     * The configuration array.
13
     *
14
     * @var array
15
     */
16
    protected $config = [
17
        'background' => 'bg-white',
18
        'icon-background' => 'red',
19
        'text' => 'dark'
20
    ];
21
22
    /**
23
     * Treat this method as a controller action.
24
     * Return view() or other content to display.
25
     */
26
    public function run()
27
    {
28
        return view('microboard::state', [
29
            'config' => $this->config,
30
            'title' => trans('microboard::pages.widgets.permissions-count.title'),
31
            'info' => trans('microboard::pages.widgets.permissions-count.info'),
32
            'icon' => 'ni ni-key-25',
33
            'count' => Permission::count()
34
        ]);
35
    }
36
37
    /**
38
     * Determine if the widget should be displayed.
39
     *
40
     * @return bool
41
     */
42
    public function shouldBeDisplayed()
43
    {
44
        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...
45
    }
46
}
47