Passed
Push — v5 ( e348bf...8a8f01 )
by Alexey
06:35
created

UsersController   B

Complexity

Total Complexity 44

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 8.3396
c 0
b 0
f 0
wmc 44
lcom 0
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A loginAsAction() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like UsersController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use UsersController, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * Users admin controller
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
class UsersController extends adminController {
12
13
    public function loginAction() {
14
        if (!Users\User::$cur->user_id) {
15
            $this->view->page(['page' => 'login', 'content' => 'login']);
16
        } else {
17
            $this->view->page(['content' => 'profile']);
18
        }
19
    }
20
21
    public function loginAsAction($userId) {
22
        $user = Users\User::get($userId);
23
        App::$cur->users->newSession($user);
24
        Tools::redirect('/', 'Теперь вы на сайте под пользователем ' . $user->name());
0 ignored issues
show
Bug introduced by
The type Tools 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...
25
    }
26
27
}
28