ListController::import()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 17
rs 10
cc 2
nc 2
nop 3
1
<?php
2
3
namespace Uccello\Core\Http\Controllers\User;
4
5
use App\User;
0 ignored issues
show
Bug introduced by
The type App\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Http\Request;
7
use Uccello\Core\Http\Controllers\Core\ListController as CoreListController;
8
use Uccello\Core\Models\Domain;
9
use Uccello\Core\Models\Module;
10
use Uccello\Core\Support\Traits\WithPrivileges;
11
use Uccello\Core\Support\Traits\WithRoles;
12
13
class ListController extends CoreListController
14
{
15
    use WithRoles;
0 ignored issues
show
introduced by
The trait Uccello\Core\Support\Traits\WithRoles requires some properties which are not provided by Uccello\Core\Http\Controllers\User\ListController: $id, $name
Loading history...
16
    use WithPrivileges;
0 ignored issues
show
Bug introduced by
The trait Uccello\Core\Support\Traits\WithPrivileges requires the property $id which is not provided by Uccello\Core\Http\Controllers\User\ListController.
Loading history...
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function process(?Domain $domain, Module $module, Request $request)
22
    {
23
        // Get default view
24
        $view = parent::process($domain, $module, $request);
25
26
        // Useful if multi domains is not used
27
        $domain = $this->domain;
28
29
        // Add data to the view
30
        $view->roles = $this->getAllRolesOnDomain($domain);
31
32
        return $view;
33
    }
34
35
    /**
36
     * Import user from another domain
37
     *
38
     * @param \Uccello\Core\Models\Domain|null $domain
39
     * @param \Uccello\Core\Models\Module $module
40
     * @param \Illuminate\Http\Request $request
41
     * @return void
42
     */
43
    public function import(?Domain $domain, Module $module, Request $request)
44
    {
45
        $this->preProcess($domain, $module, $request);
46
47
        // Useful if multi domains is not used
48
        $domain = $this->domain;
49
50
        $roleIds = (array)$request->roles;
51
52
        $user = User::find($request->user_id);
53
        if ($user) {
54
            $this->createPrivilegesForUser($domain, $user, $roleIds);
55
        }
56
57
        $route = ucroute('uccello.list', $domain, $module);
58
59
        return redirect($route);
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect($route) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type void.
Loading history...
60
    }
61
62
    /**
63
     * Build query for retrieving content
64
     *
65
     * @return \Illuminate\Database\Eloquent\Builder;
66
     */
67
    protected function buildContentQuery()
68
    {
69
        $filter = [
70
            'order' => $this->request->get('order'),
71
            'columns' => $this->request->get('columns'),
72
        ];
73
74
        // Get model model class
75
        $modelClass = $this->module->model_class;
0 ignored issues
show
Bug introduced by
The property model_class does not seem to exist on Uccello\Core\Models\Module. 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...
76
77
        // Check if the class exists
78
        if (!class_exists($modelClass) || !method_exists($modelClass, 'scopeInDomain')) {
79
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type Illuminate\Database\Eloquent\Builder.
Loading history...
80
        }
81
82
        // Filter on domain if column exists
83
        $query = $modelClass::withRoleInDomain($this->domain, $this->request->session()->get('descendants'))
84
                            ->filterBy($filter);
85
86
        // Display trash if filter is selected
87
        if ($this->isDisplayingTrash()) {
88
            $query = $query->onlyTrashed();
89
        }
90
91
        return $query;
92
    }
93
}
94