Completed
Push — master ( 8506a8...f27bf0 )
by Adam
06:27
created

UserController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 20 2
A delete() 0 12 3
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Services\UserTableService;
6
use App\Models\User;
7
8
class UserController extends Controller
9
{
10
    protected $userTableService;
11
12
    public function __construct(UserTableService $userTableService)
13
    {
14
        $this->userTableService = $userTableService;
15
    }
16
17
    public function index()
18
    {
19
        $title = trans('general.users');
20
21
        $dataset = User::select('id', 'name', 'email', 'created_at')
22
            ->paginate($this->getItemsPerPage());
23
24
        if ($dataset->isEmpty()) {
25
            $this->addFlashMessage(trans('general.no_users_in_database'), 'alert-danger');
26
        }
27
28
        $viewData = [
29
            'columns'       => $this->userTableService->getColumns(),
30
            'dataset'       => $dataset,
31
            'routeName'     => $this->userTableService->getRouteName(),
32
            'title'         => $title,
33
            'deleteMessage' => mb_strtolower(trans('general.user')).' '.mb_strtolower(trans('general.number')),
34
        ];
35
36
        return view('list', $viewData);
37
    }
38
39
    public function delete($objectId)
40
    {
41
        $object = User::find($objectId);
42
        $data = ['class' => 'alert-success', 'message' => trans('general.deleted')];
43
44
        if (!$object || $object->id === 1 /*|| $object->isAdmin()*/) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
            $data = ['class' => 'alert-danger', 'message' => trans('general.cannot_delete_admins')];
46
        } else {
47
            User::destroy($objectId);
48
        }
49
50
        return response()->json($data);
51
    }
52
}
53