Completed
Push — master ( f89f2d...eac518 )
by Nicolas
01:55
created

Polar::scriptVariables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace PolarAdmin\Polar;
4
5
use Illuminate\Support\Collection;
6
7
class Polar
8
{
9
    public static function scriptVariables()
10
    {
11
        return [
12
            'csrfToken' => csrf_token(),
13
            'userId' => auth()->id(),
0 ignored issues
show
Bug introduced by
The method id 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...
14
        ];
15
    }
16
17
    public static function userModel()
18
    {
19
        return config('polar.user_model');
20
    }
21
22
    public function admins() : Collection
23
    {
24
        $field = config('polar.authorize.field');
25
        $acceptedValues = config('polar.authorize.accepted_values');
26
27
        return self::userModel()::whereIn($field, $acceptedValues)->get();
28
    }
29
}
30