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

UsersInThisMonth::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
namespace Microboard\Widgets;
4
5
use App\User;
6
use Microboard\Foundations\Widget;
7
8
class UsersInThisMonth extends Widget
9
{
10
    /**
11
     * The configuration array.
12
     *
13
     * @var array
14
     */
15
    protected $config = [
16
        'background' => 'bg-white',
17
        'icon-background' => 'success',
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.users-in-this-month.title'),
30
            'info' => trans('microboard::pages.widgets.users-in-this-month.info'),
31
            'icon' => 'fa fa-user',
32
            'count' => User::count(),
33
            'extra' => User::whereBetween('created_at', [
34
                now()->firstOfMonth(),
35
                now()->lastOfMonth()
36
            ])->count()
37
        ]);
38
    }
39
40
    /**
41
     * Determine if the widget should be displayed.
42
     *
43
     * @return bool
44
     */
45
    public function shouldBeDisplayed()
46
    {
47
        return auth()->user()->can('viewAny', new User);
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...
48
    }
49
}
50