Skip to content

Commit 4e8be04

Browse files
committed
Simplify variable initialization using null coalescing operator - refs BT#22302
1 parent 3917784 commit 4e8be04

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

main/inc/local.inc.php

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
}
138138

139139
// parameters passed via GET
140-
$logout = isset($_GET['logout']) ? $_GET['logout'] : '';
140+
$logout = $_GET['logout'] ?? '';
141141
$gidReq = isset($_GET['gidReq']) ? (int) $_GET['gidReq'] : '';
142142

143143
// Keep a trace of the course and session from which we are getting out, to
@@ -167,7 +167,7 @@
167167

168168
// $cDir is a special url param sent from a redirection from /courses/[DIR]/index.php...
169169
// It replaces cidReq in some opportunities
170-
$cDir = isset($_GET['cDir']) && !empty($_GET['cDir']) ? $_GET['cDir'] : '';
170+
$cDir = !empty($_GET['cDir']) ? $_GET['cDir'] : '';
171171

172172
// if there is a cDir parameter in the URL and $cidReq could not be determined
173173
if (!empty($cDir) && empty($cidReq)) {
@@ -189,11 +189,11 @@
189189
$cidReq = null;
190190
}
191191

192-
$gidReset = isset($gidReset) ? $gidReset : '';
192+
$gidReset = $gidReset ?? '';
193193
// $gidReset can be set in URL-parameter
194194

195195
// parameters passed via POST
196-
$login = isset($_POST["login"]) ? $_POST["login"] : '';
196+
$login = $_POST["login"] ?? '';
197197
// register if the user is just logging in, in order to redirect him
198198
$logging_in = false;
199199

@@ -484,7 +484,7 @@
484484
// Check captcha
485485
$captchaText = $_POST['captcha'];
486486
/** @var Text_CAPTCHA $obj */
487-
$obj = isset($_SESSION['template.lib']) ? $_SESSION['template.lib'] : null;
487+
$obj = $_SESSION['template.lib'] ?? null;
488488
if ($obj) {
489489
$obj->getPhrase();
490490
if ($obj->getPhrase() != $captchaText) {
@@ -500,7 +500,7 @@
500500
}
501501

502502
// Redirect to login page
503-
if ($captchaValidated == false) {
503+
if (!$captchaValidated) {
504504
$loginFailed = true;
505505
Session::erase('_uid');
506506
Session::write('loginFailed', '1');
@@ -512,7 +512,7 @@
512512
// Check if account is blocked by captcha user extra field see function api_block_account_captcha()
513513
$blockedUntilDate = api_get_user_blocked_by_captcha($login);
514514

515-
if (isset($blockedUntilDate) && !empty($blockedUntilDate)) {
515+
if (!empty($blockedUntilDate)) {
516516
if (time() > api_strtotime($blockedUntilDate, 'UTC')) {
517517
api_clean_account_captcha($login);
518518
} else {
@@ -541,7 +541,7 @@
541541
if ($validPassword === false) {
542542
// Use external webservice to
543543
$options = api_get_configuration_value('webservice_validation');
544-
if (!empty($options) && isset($options['options']) && !empty($options['options'])) {
544+
if (!empty($options) && !empty($options['options'])) {
545545
$options = $options['options'];
546546
$soapclient = new nusoap_client($options['wsdl']);
547547
$function = $options['check_login_function'];
@@ -588,7 +588,7 @@
588588
'update_type'
589589
);
590590

591-
$update_type = isset($update_type['update_type']) ? $update_type['update_type'] : '';
591+
$update_type = $update_type['update_type'] ?? '';
592592
if (!empty($extAuthSource[$update_type]['updateUser'])
593593
&& file_exists($extAuthSource[$update_type]['updateUser'])
594594
) {
@@ -1084,7 +1084,7 @@
10841084

10851085
// if the requested course is different from the course in session
10861086
if (!empty($cidReq) && (!isset($_SESSION['_cid']) ||
1087-
(isset($_SESSION['_cid']) && $cidReq != $_SESSION['_cid']))
1087+
($cidReq != $_SESSION['_cid']))
10881088
) {
10891089
$cidReset = true;
10901090
$gidReset = true; // As groups depend from courses, group id is reset
@@ -1141,8 +1141,8 @@
11411141
Session::write('is_allowedCreateCourse', $is_allowedCreateCourse);
11421142
} else { // continue with the previous values
11431143
$_user = $_SESSION['_user'];
1144-
$is_platformAdmin = isset($_SESSION['is_platformAdmin']) ? $_SESSION['is_platformAdmin'] : false;
1145-
$is_allowedCreateCourse = isset($_SESSION['is_allowedCreateCourse']) ? $_SESSION['is_allowedCreateCourse'] : false;
1144+
$is_platformAdmin = $_SESSION['is_platformAdmin'] ?? false;
1145+
$is_allowedCreateCourse = $_SESSION['is_allowedCreateCourse'] ?? false;
11461146
}
11471147

11481148
$logoutCourseCalled = false;
@@ -1153,7 +1153,7 @@
11531153
// The value $_dont_save_user_course_access should be added before
11541154
// the call of global.inc.php see the main/inc/chat.ajax.php file
11551155
// Disables the updates in the TRACK_E_COURSE_ACCESS table
1156-
if (isset($_dont_save_user_course_access) && $_dont_save_user_course_access == true) {
1156+
if (isset($_dont_save_user_course_access) && $_dont_save_user_course_access) {
11571157
$save_course_access = false;
11581158
} else {
11591159
$logoutCourseCalled = true;
@@ -1238,7 +1238,7 @@
12381238
}
12391239
} else {
12401240
// Leave a logout time in the track_e_course_access table if we were in a course
1241-
if ($logoutCourseCalled == false) {
1241+
if (!$logoutCourseCalled) {
12421242
Event::courseLogout($logoutInfo);
12431243
}
12441244
Session::erase('_cid');
@@ -1319,7 +1319,7 @@
13191319

13201320
/* COURSE / USER REL. INIT */
13211321
$session_id = api_get_session_id();
1322-
$user_id = isset($_user['user_id']) ? $_user['user_id'] : null;
1322+
$user_id = $_user['user_id'] ?? null;
13231323

13241324
//Course permissions
13251325
//if this code is uncommented in some platforms the is_courseAdmin is not correctly saved see BT#5789
@@ -1734,7 +1734,6 @@
17341734

17351735
if (!$is_platformAdmin) {
17361736
if (!$is_courseMember &&
1737-
isset($_course['registration_code']) &&
17381737
!empty($_course['registration_code']) &&
17391738
!Session::read('course_password_'.$_course['real_id'], false)
17401739
) {
@@ -1793,32 +1792,28 @@
17931792
Session::write('is_sessionAdmin', $is_sessionAdmin);
17941793
} else {
17951794
// Continue with the previous values
1796-
$is_courseAdmin = isset($_SESSION['is_courseAdmin']) ? $_SESSION['is_courseAdmin'] : false;
1797-
$is_courseTutor = isset($_SESSION['is_courseTutor']) ? $_SESSION['is_courseTutor'] : false;
1798-
$is_session_general_coach = isset($_SESSION['is_session_general_coach']) ? $_SESSION['is_session_general_coach'] : false;
1799-
$is_courseMember = isset($_SESSION['is_courseMember']) ? $_SESSION['is_courseMember'] : false;
1800-
$is_allowed_in_course = isset($_SESSION['is_allowed_in_course']) ? $_SESSION['is_allowed_in_course'] : false;
1795+
$is_courseAdmin = $_SESSION['is_courseAdmin'] ?? false;
1796+
$is_courseTutor = $_SESSION['is_courseTutor'] ?? false;
1797+
$is_session_general_coach = $_SESSION['is_session_general_coach'] ?? false;
1798+
$is_courseMember = $_SESSION['is_courseMember'] ?? false;
1799+
$is_allowed_in_course = $_SESSION['is_allowed_in_course'] ?? false;
18011800
}
18021801

18031802
//set variable according to student_view_enabled choices
18041803
if (api_get_setting('student_view_enabled') == "true") {
18051804
$changed = false;
18061805
if (isset($_GET['isStudentView'])) {
18071806
if ($_GET['isStudentView'] == 'true') {
1808-
if (isset($_SESSION['studentview'])) {
1809-
if (!empty($_SESSION['studentview'])) {
1810-
// switching to studentview
1811-
$_SESSION['studentview'] = 'studentview';
1812-
$changed = true;
1813-
}
1807+
if (!empty($_SESSION['studentview'])) {
1808+
// switching to studentview
1809+
$_SESSION['studentview'] = 'studentview';
1810+
$changed = true;
18141811
}
18151812
} elseif ($_GET['isStudentView'] == 'false') {
1816-
if (isset($_SESSION['studentview'])) {
1817-
if (!empty($_SESSION['studentview'])) {
1818-
// switching to teacherview
1819-
$_SESSION['studentview'] = 'teacherview';
1820-
$changed = true;
1821-
}
1813+
if (!empty($_SESSION['studentview'])) {
1814+
// switching to teacherview
1815+
$_SESSION['studentview'] = 'teacherview';
1816+
$changed = true;
18221817
}
18231818
}
18241819
} elseif (!empty($_SESSION['studentview'])) {

0 commit comments

Comments
 (0)