Total Complexity | 44 |
Total Lines | 211 |
Duplicated Lines | 0 % |
Changes | 0 |
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.
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 |
||
11 | class UsersController extends Controller { |
||
|
|||
12 | |||
13 | public function indexAction() { |
||
14 | Tools::redirect('/users/cabinet/profile'); |
||
15 | } |
||
16 | |||
17 | public function cabinetAction($activeSection = '') { |
||
18 | $bread = []; |
||
19 | |||
20 | $sections = $this->module->getSnippets('cabinetSection'); |
||
21 | if (!empty($sections[$activeSection]['name'])) { |
||
22 | $this->view->setTitle($sections[$activeSection]['name'] . ' - ' . \I18n\Text::module('Users', 'Личный кабинет')); |
||
23 | $bread[] = ['text' => 'Личный кабинет', 'href' => '/users/cabinet']; |
||
24 | $bread[] = ['text' => $sections[$activeSection]['name']]; |
||
25 | } else { |
||
26 | $this->view->setTitle('Личный кабинет'); |
||
27 | $bread[] = ['text' => 'Личный кабинет']; |
||
28 | } |
||
29 | $this->view->page(['data' => compact('widgets', 'sections', 'activeSection', 'bread')]); |
||
30 | } |
||
31 | |||
32 | public function loginAction() { |
||
37 | } |
||
38 | |||
39 | public function passreAction() { |
||
44 | } |
||
45 | |||
46 | public function registrationAction() { |
||
47 | $this->view->setTitle('Регистрация'); |
||
48 | if (Users\User::$cur->user_id) { |
||
49 | Tools::redirect('/', 'Вы уже зарегистрированы'); |
||
50 | } |
||
51 | if (!empty($_POST)) { |
||
52 | $error = false; |
||
53 | if ($this->Recaptcha) { |
||
54 | $response = $this->Recaptcha->check($_POST['g-recaptcha-response']); |
||
55 | if ($response) { |
||
56 | if (!$response->success) { |
||
57 | Msg::add('Вы не прошли проверку на робота', 'danger'); |
||
58 | $error = true; |
||
59 | } |
||
60 | } else { |
||
61 | Msg::add('Произошла ошибка, попробуйте ещё раз'); |
||
62 | $error = true; |
||
63 | } |
||
64 | } |
||
65 | if (!$error) { |
||
66 | if ($this->Users->registration($_POST)) { |
||
67 | Tools::redirect('/'); |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | $this->view->setTitle('Регистрация'); |
||
72 | $bread = []; |
||
73 | $bread[] = ['text' => 'Регистрация']; |
||
74 | $this->view->page(['data' => compact('bread')]); |
||
75 | } |
||
76 | |||
77 | public function fastRegistrationAction() { |
||
108 | } |
||
109 | |||
110 | } |
||
111 | } |
||
112 | } |
||
113 | |||
114 | public function activationAction($userId = 0, $hash = '') { |
||
115 | $user = \Users\User::get((int) $userId); |
||
116 | if (!$user || !$hash || $user->activation !== (string) $hash) { |
||
117 | Tools::redirect('/', 'Во время активации произошли ошибки', 'danger'); |
||
118 | } |
||
119 | $user->activation = ''; |
||
120 | $user->save(); |
||
121 | Inji::$inst->event('Users-completeActivation', $user); |
||
122 | Tools::redirect('/', 'Вы успешно активировали ваш аккаунт', 'success'); |
||
123 | } |
||
124 | |||
125 | public function attachEmailAction() { |
||
126 | if (Users\User::$cur->mail) { |
||
127 | Tools::redirect('/', 'К вашему аккаунту уже привязан E-Mail'); |
||
128 | } |
||
129 | if (!empty($_POST['mail'])) { |
||
130 | $user_mail = trim($_POST['mail']); |
||
131 | if (!filter_var($user_mail, FILTER_VALIDATE_EMAIL)) { |
||
132 | Msg::add('Вы ввели не корректный E-mail', 'danger'); |
||
133 | } else { |
||
134 | $user = Users\User::get($user_mail, 'mail'); |
||
135 | if ($user && $user->id != Users\User::$cur->id) { |
||
136 | Msg::add('Данный E-mail уже привязан к другому аккаунту', 'danger'); |
||
137 | } else { |
||
138 | Users\User::$cur->mail = $user_mail; |
||
139 | if (!empty($this->module->config['needActivation'])) { |
||
140 | Users\User::$cur->activation = Tools::randomString(); |
||
141 | $from = 'noreply@' . INJI_DOMAIN_NAME; |
||
142 | $to = $user_mail; |
||
143 | $subject = 'Активация аккаунта на сайте ' . idn_to_utf8(INJI_DOMAIN_NAME); |
||
144 | $text = 'Для активации вашего аккаунта перейдите по ссылке <a href = "http://' . INJI_DOMAIN_NAME . '/users/activation/' . Users\User::$cur->id . '/' . Users\User::$cur->activation . '">http://' . idn_to_utf8(INJI_DOMAIN_NAME) . '/users/activation/' . Users\User::$cur->id . '/' . Users\User::$cur->activation . '</a>'; |
||
145 | Tools::sendMail($from, $to, $subject, $text); |
||
146 | Msg::add('На указанный почтовый ящик была выслана ваша ссылка для подтверждения E-Mail', 'success'); |
||
147 | } else { |
||
148 | Msg::add('Вы успешно привязали E-Mail к своему аккаунту', 'success'); |
||
149 | } |
||
150 | Users\User::$cur->save(); |
||
151 | Tools::redirect('/'); |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | $this->view->page(); |
||
156 | } |
||
157 | |||
158 | public function resendActivationAction($userId = 0) { |
||
159 | $user = \Users\User::get((int) $userId); |
||
160 | if (!$user) { |
||
161 | Tools::redirect('/', 'Не указан пользователь', 'danger'); |
||
162 | } |
||
163 | if (!$user->activation) { |
||
164 | Tools::redirect('/', 'Пользователь уже активирован'); |
||
165 | } |
||
166 | $from = 'noreply@' . INJI_DOMAIN_NAME; |
||
167 | $to = $user->mail; |
||
168 | $subject = 'Активация аккаунта на сайте ' . idn_to_utf8(INJI_DOMAIN_NAME); |
||
169 | $text = 'Для активации вашего аккаунта перейдите по ссылке <a href = "http://' . INJI_DOMAIN_NAME . '/users/activation/' . $user->id . '/' . $user->activation . '">http://' . idn_to_utf8(INJI_DOMAIN_NAME) . '/users/activation/' . $user->id . '/' . $user->activation . '</a>'; |
||
170 | Tools::sendMail($from, $to, $subject, $text); |
||
171 | Tools::redirect('/', 'На указанный почтовый ящик была выслана ваша ссылка для подтверждения E-Mail', 'success'); |
||
172 | } |
||
173 | |||
174 | public function getPartnerInfoAction($userId = 0) { |
||
222 | } |
||
223 | |||
224 | } |
||
225 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths