Passed
Push — develop ( 0fc46b...6b7c8d )
by Tony
04:19
created

HomeController::about()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Api;
6
use App\Models\Dashboard;
7
use Illuminate\Http\Request;
8
use JWTAuth;
9
10
class HomeController extends Controller
11
{
12
13
14 1
    public function redirect(Request $request)
15
    {
16 1
        $dashboard = Dashboard::where('user_id', $request->user()->user_id)->first();
17 1
        if (empty($dashboard->dashboard_id)) {
18 1
            $dashboard = new Dashboard();
19 1
            $dashboard->dashboard_name = 'Default';
20 1
            $dashboard->access         = 0;
21 1
            $request->user()->dashboards()->save($dashboard);
22
        }
23 1
        return redirect()->route('dashboard.show', ['id' => $dashboard->dashboard_id]);
24
    }
25
26
    public function index(Request $request)
27
    {
28
        $dashboards = Api::be(auth()->user())->get('/api/dashboard');
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...
29
        return view('home', ['dashboards' => $dashboards, 'request' => $request]);
30
    }
31
32 3
    public function show(Request $request)
33
    {
34 3
        $token      = JWTAuth::fromUser(auth()->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...
35 3
        $dashboards = Api::be(auth()->user())->get('/api/dashboard');
36 3
        if (Dashboard::find($request->route('dashboard_id'))) {
37 3
            $dash    = Api::be(auth()->user())->get('/api/dashboard/'.$request->route('dashboard_id'));
38 3
            $widgets = Api::be(auth()->user())->get('/api/widget');
39
        } else {
40
            return redirect()->route('home');
41
        }
42 3
        return view('home', ['dashboards' => $dashboards, 'request' => $request, 'dash_widgets' => $dash['widgets'], 'token' => $token, 'dash_details' => $dash['dashboard'], 'widgets' => $widgets]);
43
    }
44
45 1
    public function about()
46
    {
47 1
        $versions = Api::be(auth()->user())->get('/api/info');
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 1
        $stats    = Api::be(auth()->user())->get('/api/stats');
49 1
        return view('general.about', ['versions' => $versions, 'stats' => $stats]);
50
    }
51
}
52