| Conditions | 26 |
| Paths | 1538 |
| Total Lines | 82 |
| Code Lines | 55 |
| 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, $userInfo = null) |
||
| 55 | { |
||
| 56 | $no_redirection = isset($_SESSION['noredirection']) ? $_SESSION['noredirection'] : false; |
||
| 57 | |||
| 58 | if ($no_redirection) { |
||
| 59 | unset($_SESSION['noredirection']); |
||
| 60 | |||
| 61 | return; |
||
| 62 | } |
||
| 63 | |||
| 64 | $url = isset($_SESSION['request_uri']) ? Security::remove_XSS($_SESSION['request_uri']) : ''; |
||
| 65 | unset($_SESSION['request_uri']); |
||
| 66 | |||
| 67 | $afterLogin = Session::read('redirect_after_not_allow_page'); |
||
| 68 | |||
| 69 | if (!empty($afterLogin) && isset($_GET['redirect_after_not_allow_page'])) { |
||
| 70 | Session::erase('redirect_after_not_allow_page'); |
||
| 71 | self::navigate($afterLogin); |
||
| 72 | } |
||
| 73 | if (!empty($url)) { |
||
| 74 | self::navigate($url); |
||
| 75 | } elseif ($logging_in || |
||
| 76 | (isset($_REQUEST['sso_referer']) && !empty($_REQUEST['sso_referer'])) |
||
| 77 | ) { |
||
| 78 | if (isset($userInfo) && !empty($userInfo)) { |
||
| 79 | $userId = $userInfo['user_id']; |
||
| 80 | $allow = ('true' === api_get_setting('workflows.plugin_redirection_enabled')); |
||
| 81 | if ($allow) { |
||
| 82 | RedirectionPlugin::redirectUser($userId); |
||
| 83 | } |
||
| 84 | |||
| 85 | // Make sure we use the appropriate role redirection in case one has been defined |
||
| 86 | $user_status = $userInfo['status']; |
||
| 87 | switch ($user_status) { |
||
| 88 | case COURSEMANAGER: |
||
| 89 | $redir = api_get_setting('teacher_page_after_login'); |
||
| 90 | if (!empty($redir)) { |
||
| 91 | self::navigate(api_get_path(WEB_PATH).$redir); |
||
|
|
|||
| 92 | } |
||
| 93 | break; |
||
| 94 | case STUDENT: |
||
| 95 | $redir = api_get_setting('student_page_after_login'); |
||
| 96 | if (!empty($redir)) { |
||
| 97 | self::navigate(api_get_path(WEB_PATH).$redir); |
||
| 98 | } |
||
| 99 | break; |
||
| 100 | case DRH: |
||
| 101 | $redir = api_get_setting('drh_page_after_login'); |
||
| 102 | if (!empty($redir)) { |
||
| 103 | self::navigate(api_get_path(WEB_PATH).$redir); |
||
| 104 | } |
||
| 105 | break; |
||
| 106 | case SESSIONADMIN: |
||
| 107 | $redir = api_get_setting('sessionadmin_page_after_login'); |
||
| 108 | if (!empty($redir)) { |
||
| 109 | self::navigate(api_get_path(WEB_PATH).$redir); |
||
| 110 | } |
||
| 111 | break; |
||
| 112 | default: |
||
| 113 | break; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | $redirect = api_get_setting('redirect_admin_to_courses_list'); |
||
| 117 | if ('true' !== $redirect) { |
||
| 118 | // If the user is a platform admin, redirect to the main admin page |
||
| 119 | if (api_is_multiple_url_enabled()) { |
||
| 120 | // if multiple URLs are enabled, make sure he's admin of the |
||
| 121 | // current URL before redirecting |
||
| 122 | $url = api_get_current_access_url_id(); |
||
| 123 | if (api_is_platform_admin_by_id($userId, $url)) { |
||
| 124 | self::navigate(api_get_path(WEB_CODE_PATH).'admin/index.php'); |
||
| 125 | } |
||
| 126 | } else { |
||
| 127 | // if no multiple URL, then it's enough to be platform admin |
||
| 128 | if (api_is_platform_admin_by_id($userId)) { |
||
| 129 | self::navigate(api_get_path(WEB_CODE_PATH).'admin/index.php'); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | } |
||
| 133 | $page_after_login = api_get_setting('page_after_login'); |
||
| 134 | if (!empty($page_after_login)) { |
||
| 135 | self::navigate(api_get_path(WEB_PATH).$page_after_login); |
||
| 136 | } |
||
| 170 |