Completed
Push — master ( cd2ebb...7ad1ba )
by Tony
11s
created

HomeController::show()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.004

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 9
cts 10
cp 0.9
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
crap 2.004
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Dingo\Api\Http;
6
use Dingo\Api\Routing\Helpers;
7
use Illuminate\Http\Request;
8
use App\Models\Dashboard;
9
use JWTAuth;
10
use Tymon\JWTAuth\Exceptions\JWTException;
11
12
class HomeController extends Controller
13
{
14
    use Helpers;
15
16 4
    public function __construct(Request $request) {
1 ignored issue
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17 4
        $this->middleware('auth');
18 4
    }
19
20
    public function redirect(Request $request)
21
    {
22
        $dashboard = Dashboard::where('user_id', $request->user()->user_id)->first();
23
        if (empty($dashboard->dashboard_id))
24
        {
25
            $dashboard = new dashboard;
26
            $dashboard->dashboard_name = 'Default';
0 ignored issues
show
Documentation introduced by
The property dashboard_name does not exist on object<App\Models\Dashboard>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
27
            $dashboard->access         = 0;
0 ignored issues
show
Documentation introduced by
The property access does not exist on object<App\Models\Dashboard>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
28
            $request->user()->dashboards()->save($dashboard);
29
        }
30
        return redirect()->route('dashboard.show', ['id' => $dashboard->dashboard_id]);
31
    }
32
33
    public function index(Request $request) {
34
        $dashboards = $this->api->be(auth()->user())->get('/api/dashboard');
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
        return view('home', ['dashboards' => $dashboards, 'request' => $request]);
36
    }
37
38 2
    public function show(Request $request)
39
    {
40 2
        $token      = JWTAuth::fromUser(auth()->user());
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41 2
        $dashboards = $this->api->be(auth()->user())->get('/api/dashboard');
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42 2
        if (Dashboard::find($request->route('dashboard_id')))
43 2
        {
44 2
            $dash    = $this->api->be(auth()->user())->get('/api/dashboard/'.$request->route('dashboard_id'));
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45 2
            $widgets = $this->api->be(auth()->user())->get('/api/widget');
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46 2
        }
47
        else {
48
            return redirect()->route('home');
49
        }
50 2
        return view('home', ['dashboards' => $dashboards, 'request' => $request, 'dash_widgets' => $dash['widgets'], 'token' => $token, 'dash_details' => $dash['dashboard'], 'widgets' => $widgets]);
51
    }
52
53 1
    public function about() {
54 1
        $versions = $this->api->be(auth()->user())->get('/api/info');
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55 1
        $stats    = $this->api->be(auth()->user())->get('/api/stats');
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56 1
        return view('general.about', ['versions' => $versions, 'stats' => $stats]);
57
    }
58
}
59