UserController::postProfile()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php namespace Distilleries\Expendable\Http\Controllers\Backend;
2
3
use Distilleries\Expendable\Contracts\LayoutManagerContract;
4
use Distilleries\Expendable\Http\Datatables\User\UserDatatable;
5
use Distilleries\Expendable\Http\Forms\User\UserForm;
6
use Distilleries\Expendable\Http\Controllers\Backend\Base\BaseComponent;
7
use Distilleries\Expendable\Models\User;
8
use Illuminate\Contracts\Auth\Guard;
9
use Illuminate\Http\Request;
10
11
class UserController extends BaseComponent {
12
13
14 26
    public function __construct(UserDatatable $datatable, UserForm $form, User $model, LayoutManagerContract $layoutManager)
15
    {
16 26
        parent::__construct($model, $layoutManager);
17 26
        $this->datatable = $datatable;
18 26
        $this->form      = $form;
19
    }
20
21
    // ------------------------------------------------------------------------------------------------
22
    // ------------------------------------------------------------------------------------------------
23
    // ------------------------------------------------------------------------------------------------
24
25
26 4
    public function getProfile(Guard $auth)
27
    {
28 4
        return $this->getEdit($auth->user()->getKey());
29
    }
30
31
    // ------------------------------------------------------------------------------------------------
32
33 4
    public function postProfile(Request $request, Guard $auth)
34
    {
35 4
        if ($auth->user()->getAuthIdentifier() == $request->get($this->model->getKeyName()))
36
        {
37 2
            $this->postEdit($request);
38
39 2
            return $this->getProfile($auth);
40
        }
41
42 2
        abort(403, trans('permission-util::errors.unthorized'));
0 ignored issues
show
Bug introduced by
It seems like trans('permission-util::errors.unthorized') can also be of type array; however, parameter $message of abort() 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

42
        abort(403, /** @scrutinizer ignore-type */ trans('permission-util::errors.unthorized'));
Loading history...
43
    }
44
45
    // ------------------------------------------------------------------------------------------------
46
47 2
    public function postSearchWithRole(Request $request)
48
    {
49 2
        $query = $this->model->where('role_id', '=', $request->get('role'));
50 2
        $this->postSearch($request, $query);
51
52 2
        return $this->postSearch($request, $query);
53
    }
54
55
56
    public function postUnLock(Request $request) {
57
58
        $model = $this->model->findOrFail($request->get('id'));
59
        $model->nb_of_try = 0;
0 ignored issues
show
Bug introduced by
The property nb_of_try does not seem to exist on Distilleries\Expendable\Models\BaseModel. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
60
        $model->save();
61
62
        return redirect()->back();
63
    }
64
65
66
    public function postLock(Request $request) {
67
68
        $model = $this->model->findOrFail($request->get('id'));
69
        $model->nb_of_try = config('expendable.auth.nb_of_try');
0 ignored issues
show
Bug introduced by
The property nb_of_try does not seem to exist on Distilleries\Expendable\Models\BaseModel. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
70
        $model->save();
71
72
        return redirect()->back();
73
    }
74
75
}