From c25857a73fdb23c50907f49a1253ff4fd56b8644 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Wed, 10 May 2023 10:02:38 +0800 Subject: [PATCH] MDL-76842 auth_lti: remove redundant conditional logic and cast --- auth/lti/auth.php | 4 ++-- auth/lti/tests/auth_test.php | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/auth/lti/auth.php b/auth/lti/auth.php index 9bf8975868e..c5fb73ebb03 100644 --- a/auth/lti/auth.php +++ b/auth/lti/auth.php @@ -181,7 +181,7 @@ class auth_plugin_lti extends \auth_plugin_base { unset($member['picture']); if ($binduser = $this->get_user_binding($iss, $member['user_id'])) { - $user = \core_user::get_user((int) $binduser); + $user = \core_user::get_user($binduser); $this->update_user_account($user, $member, $iss); return \core_user::get_user($user->id); } else { @@ -223,7 +223,7 @@ class auth_plugin_lti extends \auth_plugin_base { } if ($binduser = $this->get_user_binding($launchdata['iss'], $launchdata['sub'])) { - $user = \core_user::get_user((int) $binduser); + $user = \core_user::get_user($binduser); $this->update_user_account($user, $launchdata, $launchdata['iss']); return \core_user::get_user($user->id); } else { diff --git a/auth/lti/tests/auth_test.php b/auth/lti/tests/auth_test.php index 167aed38f9e..37e291fb7c3 100644 --- a/auth/lti/tests/auth_test.php +++ b/auth/lti/tests/auth_test.php @@ -220,7 +220,7 @@ class auth_test extends \advanced_testcase { $auth = get_auth_plugin('lti'); // When testing platform users who have authenticated before, make that first auth call. - if (!empty($launchdata['has_authenticated_before']) && $launchdata['has_authenticated_before']) { + if (!empty($launchdata['has_authenticated_before'])) { $mockjwtdata = $this->get_mock_launchdata_for_user($launchdata['user']); $firstauthuser = $auth->find_or_create_user_from_launch($mockjwtdata); } @@ -261,8 +261,8 @@ class auth_test extends \advanced_testcase { // Verify user count is correct. i.e. no user is created when migration claim is correctly processed or when // the user has authenticated with the tool before. - $numnewusers = (!empty($expected['migrated']) && $expected['migrated']) ? 0 : 1; - $numnewusers = (!empty($launchdata['has_authenticated_before']) && $launchdata['has_authenticated_before']) ? + $numnewusers = (!empty($expected['migrated'])) ? 0 : 1; + $numnewusers = (!empty($launchdata['has_authenticated_before'])) ? 0 : $numnewusers; $this->assertEquals($numnewusers, $countusersafter - $countusersbefore); @@ -294,11 +294,11 @@ class auth_test extends \advanced_testcase { } // Verify picture sync occurs, if expected. - if (!empty($expected['syncpicture']) && $expected['syncpicture']) { + if (!empty($expected['syncpicture'])) { $this->verify_user_profile_image_updated($user->id); } - if (!empty($expected['migrated']) && $expected['migrated']) { + if (!empty($expected['migrated'])) { // If migrated, verify the user account is reusing the legacy user account. $legacyuserids = array_column($legacyusers, 'id'); $this->assertContains($user->id, $legacyuserids); @@ -799,7 +799,7 @@ class auth_test extends \advanced_testcase { $auth = get_auth_plugin('lti'); // When testing platform users who have authenticated before, make that first auth call. - if (!empty($memberdata['has_authenticated_before']) && $memberdata['has_authenticated_before']) { + if (!empty($memberdata['has_authenticated_before'])) { $mockmemberdata = $this->get_mock_member_data_for_user($memberdata['user'], $memberdata['legacy_user_id'] ?? ''); $firstauthuser = $auth->find_or_create_user_from_membership($mockmemberdata, $iss, @@ -834,8 +834,8 @@ class auth_test extends \advanced_testcase { // Verify user count is correct. i.e. no user is created when migration claim is correctly processed or when // the user has authenticated with the tool before. - $numnewusers = (!empty($expected['migrated']) && $expected['migrated']) ? 0 : 1; - $numnewusers = (!empty($memberdata['has_authenticated_before']) && $memberdata['has_authenticated_before']) ? + $numnewusers = (!empty($expected['migrated'])) ? 0 : 1; + $numnewusers = (!empty($memberdata['has_authenticated_before'])) ? 0 : $numnewusers; $this->assertEquals($numnewusers, $countusersafter - $countusersbefore); @@ -866,7 +866,7 @@ class auth_test extends \advanced_testcase { break; } - if (!empty($expected['migrated']) && $expected['migrated']) { + if (!empty($expected['migrated'])) { // If migrated, verify the user account is reusing the legacy user account. $legacyuserids = array_column($legacyusers, 'id'); $this->assertContains($user->id, $legacyuserids);