RestoreUserController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 25
c 1
b 0
f 1
dl 0
loc 52
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A userReActivate() 0 32 3
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\User;
6
use Carbon\Carbon;
7
use Illuminate\Http\Request;
8
9
class RestoreUserController extends ProfilesController
10
{
11
    /**
12
     * Create a new controller instance.
13
     *
14
     * @return void
15
     */
16
    public function __construct()
17
    {
18
        $this->middleware('web');
19
    }
20
21
    /**
22
     * User Account Restore.
23
     *
24
     * @param \Illuminate\Http\Request $request
25
     * @param string                   $token
26
     *
27
     * @return \Illuminate\Http\Response
28
     */
29
    public function userReActivate(Request $request, $token)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

29
    public function userReActivate(/** @scrutinizer ignore-unused */ Request $request, $token)

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

Loading history...
30
    {
31
        $userKeys = new ProfilesController();
32
        $sepKey = $userKeys->getSeperationKey();
33
        $userIdKey = $userKeys->getIdMultiKey();
34
        $restoreKey = config('settings.restoreKey');
35
        $encrypter = config('settings.restoreUserEncType');
36
        $level5 = base64_decode($token);
37
        $level4 = openssl_decrypt($level5, $encrypter, $restoreKey);
38
        $level3 = base64_decode($level4);
39
        $level2 = urldecode($level3);
40
        $level1[] = explode($sepKey, $level2);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$level1 was never initialized. Although not strictly required by PHP, it is generally a good practice to add $level1 = array(); before regardless.
Loading history...
41
        $uuid = $level1[0][0];
0 ignored issues
show
Unused Code introduced by
The assignment to $uuid is dead and can be removed.
Loading history...
42
        $userId = $level1[0][1] / $userIdKey;
43
        $user = SoftDeletesController::getDeletedUser($userId);
44
45
        if (! is_object($user)) {
46
            abort(500);
47
        }
48
49
        $deletedDate = $user->deleted_at;
0 ignored issues
show
Bug introduced by
The property deleted_at does not seem to exist on Illuminate\Http\Response.
Loading history...
50
        $currentDate = Carbon::now();
51
        $daysDeleted = $currentDate->diffInDays($deletedDate);
52
        $cutoffDays = config('settings.restoreUserCutoff');
53
54
        if ($daysDeleted >= $cutoffDays) {
55
            return redirect('/login')->with('error', trans('profile.errorRestoreUserTime'));
56
        }
57
58
        $user->restore();
59
60
        return redirect('/login')->with('success', trans('profile.successUserRestore', ['username' => $user->name]));
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Illuminate\Http\Response.
Loading history...
61
    }
62
}
63