Passed
Push — master ( 1ffd02...b93f0b )
by Bertrand
06:21
created

OAuthController::logout()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
4
namespace App\Http\Controllers\Api;
5
6
use App\User;
7
use Illuminate\Http\Request;
8
use Illuminate\Routing\Controller as BaseController;
9
use Illuminate\Support\Facades\Auth;
10
11
12
class OAuthController extends BaseController
13
{
14
    public function userByToken(Request $request)
15
    {
16
        $token = $request->input('wiki_token', null);
17
18
        if($token === null || $token === ''){
19
            return ['error' => 'invalid_token'];
20
        }
21
        $user = User::where('wiki_token', $token)->first();
22
23
        if($user === null){
24
            return ['error' => 'invalid_token'];
25
        }
26
27
        return [
28
            'id' => $user->uuid,
0 ignored issues
show
Bug Best Practice introduced by
The property uuid does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
29
            'name' => ucfirst($user->firstname).' '.ucfirst($user->lastname),
0 ignored issues
show
Bug Best Practice introduced by
The property lastname does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
It seems like $user->firstname can also be of type Illuminate\Database\Eloq...uent\Relations\Relation and Illuminate\Database\Eloquent\Relations\Relation; however, parameter $str of ucfirst() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
            'name' => ucfirst(/** @scrutinizer ignore-type */ $user->firstname).' '.ucfirst($user->lastname),
Loading history...
Bug Best Practice introduced by
The property firstname does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
30
            'realname' => ucfirst($user->firstname).' '.ucfirst($user->lastname),
31
            'email' => $user->email,
0 ignored issues
show
Bug Best Practice introduced by
The property email does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
32
            'avatar' => $user->adminlte_image()
33
        ];
34
    }
35
36
    public function logout()
37
    {
38
        $user = Auth::user();
39
        if(isset($user)){
40
            $user->wiki_token = '';
0 ignored issues
show
Bug Best Practice introduced by
The property wiki_token does not exist on App\User. Since you implemented __set, consider adding a @property annotation.
Loading history...
41
            $user->save();
42
            Auth::logout();
43
        }
44
        redirect(config('neayi.wiki_url'));
45
    }
46
}
47