InviteController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A expired() 0 3 1
A accept() 0 14 2
A deny() 0 7 1
A __construct() 0 3 1
1
<?php
2
3
namespace Thinktomorrow\Chief\App\Http\Controllers\Back\Users;
4
5
use Illuminate\Http\Request;
6
use Thinktomorrow\Chief\Admin\Users\Invites\Application\AcceptInvite;
7
use Thinktomorrow\Chief\Admin\Users\Invites\Application\DenyInvite;
8
use Thinktomorrow\Chief\Admin\Users\Invites\Invitation;
9
use Thinktomorrow\Chief\App\Http\Controllers\Controller;
10
11
class InviteController extends Controller
12
{
13
    public function __construct()
14
    {
15
        $this->middleware(['chief-validate-invite'])->except('expired');
16
    }
17
18
    /**
19
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
20
     */
21
    public function expired()
22
    {
23
        return view('chief::admin.users.invite-expired');
24
    }
25
26
    public function accept(Request $request)
27
    {
28
        $invitation = Invitation::findByToken($request->token);
29
30
        app(AcceptInvite::class)->handle($invitation);
0 ignored issues
show
Bug introduced by
It seems like $invitation can also be of type Illuminate\Database\Eloq...elations\HasManyThrough and Illuminate\Database\Eloq...Relations\HasOneThrough and null; however, parameter $invitation of Thinktomorrow\Chief\Admi...\AcceptInvite::handle() does only seem to accept Thinktomorrow\Chief\Admin\Users\Invites\Invitation, 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

30
        app(AcceptInvite::class)->handle(/** @scrutinizer ignore-type */ $invitation);
Loading history...
31
32
        // Log user into the system and proceed to start page
33
        auth()->guard('chief')->login($invitation->invitee);
0 ignored issues
show
Bug introduced by
The property invitee does not seem to exist on Illuminate\Database\Eloq...elations\HasManyThrough.
Loading history...
Bug introduced by
The property invitee does not seem to exist on Illuminate\Database\Eloq...Relations\HasOneThrough.
Loading history...
34
35
        if (is_null($invitation->invitee->password)) {
0 ignored issues
show
introduced by
The condition is_null($invitation->invitee->password) is always false.
Loading history...
36
            return redirect()->route('chief.back.password.edit');
37
        }
38
39
        return redirect()->route('chief.back.dashboard.getting-started');
40
    }
41
42
    /**
43
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
44
     */
45
    public function deny(Request $request)
46
    {
47
        $invitation = Invitation::findByToken($request->token);
48
49
        app(DenyInvite::class)->handle($invitation);
0 ignored issues
show
Bug introduced by
It seems like $invitation can also be of type Illuminate\Database\Eloq...elations\HasManyThrough and Illuminate\Database\Eloq...Relations\HasOneThrough and null; however, parameter $invitation of Thinktomorrow\Chief\Admi...on\DenyInvite::handle() does only seem to accept Thinktomorrow\Chief\Admin\Users\Invites\Invitation, 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

49
        app(DenyInvite::class)->handle(/** @scrutinizer ignore-type */ $invitation);
Loading history...
50
51
        return view('chief::admin.users.invite-denied');
52
    }
53
}
54