Conditions | 24 |
Paths | 1129 |
Total Lines | 85 |
Code Lines | 58 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
54 | public static function session_request_uri($logging_in = false, $user_id = null) |
||
55 | { |
||
56 | $no_redirection = $_SESSION['noredirection'] ?? false; |
||
57 | $no_redirection = $GLOBALS['noredirection'] ?? $no_redirection; |
||
58 | |||
59 | if ($no_redirection) { |
||
60 | unset($_SESSION['noredirection']); |
||
61 | unset($GLOBALS['noredirection']); |
||
62 | |||
63 | return; |
||
64 | } |
||
65 | |||
66 | $url = isset($_SESSION['request_uri']) ? Security::remove_XSS($_SESSION['request_uri']) : ''; |
||
67 | |||
68 | $afterLogin = Session::read('redirect_after_not_allow_page'); |
||
69 | |||
70 | if (!empty($afterLogin) && isset($_GET['redirect_after_not_allow_page'])) { |
||
71 | Session::erase('redirect_after_not_allow_page'); |
||
72 | self::navigate($afterLogin); |
||
73 | } |
||
74 | if (!empty($url)) { |
||
75 | $_SESSION['custom_request_uri'] = $_SERVER['REQUEST_URI']; |
||
76 | unset($_SESSION['request_uri']); |
||
77 | self::navigate($url); |
||
78 | } elseif ($logging_in || !empty($_REQUEST['sso_referer'])) { |
||
79 | if (!empty($user_id)) { |
||
80 | $allow = api_get_configuration_value('plugin_redirection_enabled'); |
||
81 | if ($allow) { |
||
82 | $allow = api_get_configuration_value('plugin_redirection_enabled'); |
||
83 | if ($allow) { |
||
84 | RedirectionPlugin::redirectUser($user_id); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | // Make sure we use the appropriate role redirection in case one has been defined |
||
89 | $user_status = api_get_user_status($user_id); |
||
90 | switch ($user_status) { |
||
91 | case COURSEMANAGER: |
||
92 | $redir = api_get_setting('teacher_page_after_login'); |
||
93 | if (!empty($redir)) { |
||
94 | self::navigate(api_get_path(WEB_PATH).$redir); |
||
95 | } |
||
96 | break; |
||
97 | case STUDENT: |
||
98 | $redir = api_get_setting('student_page_after_login'); |
||
99 | if (!empty($redir)) { |
||
100 | self::navigate(api_get_path(WEB_PATH).$redir); |
||
101 | } |
||
102 | break; |
||
103 | case DRH: |
||
104 | $redir = api_get_setting('drh_page_after_login'); |
||
105 | if (!empty($redir)) { |
||
106 | self::navigate(api_get_path(WEB_PATH).$redir); |
||
107 | } |
||
108 | break; |
||
109 | case SESSIONADMIN: |
||
110 | $redir = api_get_setting('sessionadmin_page_after_login'); |
||
111 | if (!empty($redir)) { |
||
112 | self::navigate(api_get_path(WEB_PATH).$redir); |
||
113 | } |
||
114 | break; |
||
115 | default: |
||
116 | break; |
||
117 | } |
||
118 | } |
||
119 | $redirect = api_get_setting('redirect_admin_to_courses_list'); |
||
120 | if ('true' !== $redirect) { |
||
121 | // If the user is a platform admin, redirect to the main admin page |
||
122 | if (api_is_multiple_url_enabled()) { |
||
123 | // if multiple URLs are enabled, make sure he's admin of the |
||
124 | // current URL before redirecting |
||
125 | $urlId = api_get_current_access_url_id(); |
||
126 | if (api_is_platform_admin_by_id($user_id, $urlId)) { |
||
127 | self::navigate(api_get_path(WEB_CODE_PATH).'admin/index.php'); |
||
128 | } |
||
129 | } else { |
||
130 | // if no multiple URL, then it's enough to be platform admin |
||
131 | if (api_is_platform_admin_by_id($user_id)) { |
||
132 | self::navigate(api_get_path(WEB_CODE_PATH).'admin/index.php'); |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | $page_after_login = api_get_setting('page_after_login'); |
||
137 | if (!empty($page_after_login)) { |
||
138 | self::navigate(api_get_path(WEB_PATH).$page_after_login); |
||
139 | } |
||
173 |