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

HomeController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A redirect() 0 11 2
A index() 0 5 1
A show() 0 12 2
A about() 0 6 1
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