Polar   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 0
cbo 0
dl 0
loc 25
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A userModel() 0 4 1
A scriptVariables() 0 9 1
A admins() 0 7 1
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
            'route' => config('polar.route'),
15
            'api_route' => config('polar.api_route'),
16
        ];
17
    }
18
19
    public static function userModel()
20
    {
21
        return config('polar.user_model');
22
    }
23
24
    public function admins() : Collection
25
    {
26
        $field = config('polar.authorize.field');
27
        $acceptedValues = config('polar.authorize.accepted_values');
28
29
        return self::userModel()::whereIn($field, $acceptedValues)->get();
30
    }
31
}
32