Skip to content

Commit eff708b

Browse files
author
dustinhuynh
committed
Reformating code for CI test
1 parent 2f15b3b commit eff708b

14 files changed

+354
-409
lines changed

auth.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@
2828
use auth_userkey\userkey_manager_interface;
2929
use core_external\external_value;
3030

31-
require_once($CFG->libdir.'/authlib.php');
31+
require_once($CFG->libdir . '/authlib.php');
3232
require_once($CFG->dirroot . '/user/lib.php');
3333

3434
/**
3535
* User key authentication plugin.
3636
*/
3737
class auth_plugin_userkey extends auth_plugin_base {
38-
3938
/**
4039
* Default mapping field.
4140
*/
@@ -53,7 +52,7 @@ class auth_plugin_userkey extends auth_plugin_base {
5352
*
5453
* @var array
5554
*/
56-
protected $defaults = array(
55+
protected $defaults = [
5756
'mappingfield' => self::DEFAULT_MAPPING_FIELD,
5857
'keylifetime' => 60,
5958
'iprestriction' => 0,
@@ -62,7 +61,7 @@ class auth_plugin_userkey extends auth_plugin_base {
6261
'ssourl' => '',
6362
'createuser' => false,
6463
'updateuser' => false,
65-
);
64+
];
6665

6766
/**
6867
* Constructor.
@@ -297,14 +296,16 @@ protected function create_user(array $data) {
297296
throw new invalid_parameter_exception('Unable to create user, missing value(s): ' . implode(',', $missingfields));
298297
}
299298

300-
if ($DB->record_exists('user', array('username' => $user['username'], 'mnethostid' => $CFG->mnet_localhost_id))) {
301-
throw new invalid_parameter_exception('Username already exists: '.$user['username']);
299+
if ($DB->record_exists('user', ['username' => $user['username'], 'mnethostid' => $CFG->mnet_localhost_id])) {
300+
throw new invalid_parameter_exception('Username already exists: ' . $user['username']);
302301
}
303302
if (!validate_email($user['email'])) {
304-
throw new invalid_parameter_exception('Email address is invalid: '.$user['email']);
305-
} else if (empty($CFG->allowaccountssameemail) &&
306-
$DB->record_exists('user', array('email' => $user['email'], 'mnethostid' => $user['mnethostid']))) {
307-
throw new invalid_parameter_exception('Email address already exists: '.$user['email']);
303+
throw new invalid_parameter_exception('Email address is invalid: ' . $user['email']);
304+
} else if (
305+
empty($CFG->allowaccountssameemail) &&
306+
$DB->record_exists('user', ['email' => $user['email'], 'mnethostid' => $user['mnethostid']])
307+
) {
308+
throw new invalid_parameter_exception('Email address already exists: ' . $user['email']);
308309
}
309310

310311
$userid = user_create_user($user);
@@ -341,20 +342,20 @@ protected function update_user(\stdClass $user, array $data) {
341342
if (
342343
$user->username != $userdata['username']
343344
&&
344-
$DB->record_exists('user', array('username' => $userdata['username'], 'mnethostid' => $CFG->mnet_localhost_id))
345+
$DB->record_exists('user', ['username' => $userdata['username'], 'mnethostid' => $CFG->mnet_localhost_id])
345346
) {
346-
throw new invalid_parameter_exception('Username already exists: '.$userdata['username']);
347+
throw new invalid_parameter_exception('Username already exists: ' . $userdata['username']);
347348
}
348349
if (!validate_email($userdata['email'])) {
349-
throw new invalid_parameter_exception('Email address is invalid: '.$userdata['email']);
350+
throw new invalid_parameter_exception('Email address is invalid: ' . $userdata['email']);
350351
} else if (
351352
empty($CFG->allowaccountssameemail)
352353
&&
353354
$user->email != $userdata['email']
354355
&&
355-
$DB->record_exists('user', array('email' => $userdata['email'], 'mnethostid' => $CFG->mnet_localhost_id))
356+
$DB->record_exists('user', ['email' => $userdata['email'], 'mnethostid' => $CFG->mnet_localhost_id])
356357
) {
357-
throw new invalid_parameter_exception('Email address already exists: '.$userdata['email']);
358+
throw new invalid_parameter_exception('Email address already exists: ' . $userdata['email']);
358359
}
359360
$userdata['id'] = $user->id;
360361

@@ -402,10 +403,10 @@ protected function get_user(array $data) {
402403

403404
$mappingfield = $this->get_mapping_field();
404405

405-
$params = array(
406+
$params = [
406407
$mappingfield => $data[$mappingfield],
407408
'mnethostid' => $CFG->mnet_localhost_id,
408-
);
409+
];
409410

410411
$user = $DB->get_record('user', $params);
411412

@@ -476,11 +477,11 @@ public function get_login_url($data) {
476477
* @return array
477478
*/
478479
public function get_allowed_mapping_fields() {
479-
return array(
480+
return [
480481
'username' => get_string('username'),
481482
'email' => get_string('email'),
482483
'idnumber' => get_string('idnumber'),
483-
);
484+
];
484485
}
485486

486487
/**
@@ -493,34 +494,34 @@ protected function get_mapping_parameter() {
493494

494495
switch ($mappingfield) {
495496
case 'username':
496-
$parameter = array(
497+
$parameter = [
497498
'username' => new external_value(
498499
PARAM_USERNAME,
499500
'Username'
500501
),
501-
);
502+
];
502503
break;
503504

504505
case 'email':
505-
$parameter = array(
506+
$parameter = [
506507
'email' => new external_value(
507508
PARAM_EMAIL,
508509
'A valid email address'
509510
),
510-
);
511+
];
511512
break;
512513

513514
case 'idnumber':
514-
$parameter = array(
515+
$parameter = [
515516
'idnumber' => new external_value(
516517
PARAM_RAW,
517518
'An arbitrary ID code number perhaps from the institution'
518519
),
519-
);
520+
];
520521
break;
521522

522523
default:
523-
$parameter = array();
524+
$parameter = [];
524525
break;
525526
}
526527

@@ -533,7 +534,7 @@ protected function get_mapping_parameter() {
533534
* @return array
534535
*/
535536
protected function get_user_fields_parameters() {
536-
$parameters = array();
537+
$parameters = [];
537538

538539
if ($this->is_ip_restriction_enabled()) {
539540
$parameters['ip'] = new external_value(
@@ -594,7 +595,6 @@ protected function should_login_redirect() {
594595
if (isset($this->config->ssourl) && $this->config->ssourl != '' && !$skipsso) {
595596
return true;
596597
}
597-
598598
}
599599

600600
/**

classes/core_userkey_manager.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2525
*/
2626
class core_userkey_manager implements userkey_manager_interface {
27-
2827
/**
2928
* This script script required by core create_user_key().
3029
*/
@@ -108,10 +107,10 @@ public function delete_keys($userid) {
108107
public function validate_key($keyvalue) {
109108
global $DB;
110109

111-
$options = array(
110+
$options = [
112111
'script' => self::CORE_USER_KEY_MANAGER_SCRIPT,
113-
'value' => $keyvalue
114-
);
112+
'value' => $keyvalue,
113+
];
115114

116115
if (!$key = $DB->get_record('user_private_key', $options)) {
117116
throw new \moodle_exception('invalidkey');
@@ -123,7 +122,7 @@ public function validate_key($keyvalue) {
123122

124123
$this->validate_ip_address($key);
125124

126-
if (!$user = $DB->get_record('user', array('id' => $key->userid))) {
125+
if (!$user = $DB->get_record('user', ['id' => $key->userid])) {
127126
throw new \moodle_exception('invaliduserid');
128127
}
129128
return $key;

classes/privacy/provider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3636
*/
3737
class provider implements null_provider {
38-
3938
use legacy_polyfill;
4039

4140
/**
@@ -47,5 +46,4 @@ class provider implements null_provider {
4746
public static function _get_reason() {
4847
return 'privacy:metadata';
4948
}
50-
5149
}

classes/userkey_manager_interface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,4 @@ public function delete_keys($userid);
5757
* @throws \moodle_exception If provided key is not valid.
5858
*/
5959
public function validate_key($keyvalue);
60-
6160
}

db/access.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424

2525
defined('MOODLE_INTERNAL') || die();
2626

27-
$capabilities = array(
28-
'auth/userkey:generatekey' => array(
29-
'riskbitmask' => RISK_PERSONAL | RISK_SPAM | RISK_XSS ,
27+
$capabilities = [
28+
'auth/userkey:generatekey' => [
29+
'riskbitmask' => RISK_PERSONAL | RISK_SPAM | RISK_XSS,
3030

3131
'captype' => 'write',
3232
'contextlevel' => CONTEXT_SYSTEM,
33-
'archetypes' => array(
34-
),
35-
),
36-
);
33+
'archetypes' => [
34+
],
35+
],
36+
];

db/services.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@
2424

2525
defined('MOODLE_INTERNAL') || die;
2626

27-
$functions = array(
28-
'auth_userkey_request_login_url' => array(
27+
$functions = [
28+
'auth_userkey_request_login_url' => [
2929
'classname' => 'auth_userkey_external',
3030
'methodname' => 'request_login_url',
3131
'classpath' => 'auth/userkey/externallib.php',
3232
'description' => 'Return one time key based login URL',
3333
'type' => 'write',
3434
'capabilities' => 'auth/userkey:generatekey',
35-
)
36-
);
35+
],
36+
];
3737

38-
$services = array(
39-
'User key authentication web service' => array(
40-
'functions' => array ('auth_userkey_request_login_url'),
38+
$services = [
39+
'User key authentication web service' => [
40+
'functions' => ['auth_userkey_request_login_url'],
4141
'restrictedusers' => 1,
4242
'enabled' => 1,
43-
)
44-
);
43+
],
44+
];

db/upgrade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function xmldb_auth_userkey_upgrade($oldversion) {
3333

3434
if ($oldversion < 2018050200) {
3535
// Confirm all previously created users.
36-
$DB->execute("UPDATE {user} SET confirmed=? WHERE auth=?", array(1, 'userkey'));
36+
$DB->execute("UPDATE {user} SET confirmed=? WHERE auth=?", [1, 'userkey']);
3737
upgrade_plugin_savepoint(true, 2018050200, 'auth', 'userkey');
3838
}
3939

externallib.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,18 @@
3939
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4040
*/
4141
class auth_userkey_external extends external_api {
42-
4342
/**
4443
* Return request_login_url webservice parameters.
4544
*
4645
* @return \external_function_parameters
4746
*/
4847
public static function request_login_url_parameters() {
4948
return new external_function_parameters(
50-
array(
49+
[
5150
'user' => new external_single_structure(
5251
get_auth_plugin('userkey')->get_request_login_url_user_parameters()
53-
)
54-
)
52+
),
53+
]
5554
);
5655
}
5756

@@ -77,9 +76,9 @@ public static function request_login_url($user) {
7776
$auth = get_auth_plugin('userkey');
7877
$loginurl = $auth->get_login_url($user);
7978

80-
return array(
79+
return [
8180
'loginurl' => $loginurl,
82-
);
81+
];
8382
}
8483

8584
/**
@@ -89,10 +88,9 @@ public static function request_login_url($user) {
8988
*/
9089
public static function request_login_url_returns() {
9190
return new external_single_structure(
92-
array(
91+
[
9392
'loginurl' => new external_value(PARAM_RAW, 'Login URL for a user to log in'),
94-
)
93+
]
9594
);
9695
}
97-
9896
}

lang/en/auth_userkey.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
*/
2424

2525
defined('MOODLE_INTERNAL') || die;
26-
27-
$string['pluginname'] = 'User key authentication';
2826
$string['auth_userkeydescription'] = 'Log in to Moodle using one time user key.';
29-
$string['mappingfield'] = 'Mapping field';
30-
$string['mappingfield_desc'] = 'This user field will be used to find relevant user in the LMS.';
27+
$string['createuser'] = 'Create user?';
28+
$string['createuser_desc'] = 'If enabled, a new user will be created if fail to find one in LMS.';
29+
$string['incorrectkeylifetime'] = 'User key life time should be a number';
30+
$string['incorrectlogout'] = 'Incorrect logout request';
31+
$string['incorrectredirecturl'] = 'You should provide valid URL';
32+
$string['incorrectssourl'] = 'You should provide valid URL';
3133
$string['iprestriction'] = 'IP restriction';
3234
$string['iprestriction_desc'] = 'If enabled, a web call has to contain "ip" parameter when requesting login URL.
3335
A user has to have provided IP to be able to use a key to login to LMS.';
@@ -37,20 +39,17 @@
3739
\nIf the route to either the system issuing tokens or this Moodle is via a private address range then set this value to 10.0.0.0/8;172.16.0.0/12;192.168.0.0/16";
3840
$string['keylifetime'] = 'User key life time';
3941
$string['keylifetime_desc'] = 'Life time in seconds of the each user login key.';
40-
$string['incorrectkeylifetime'] = 'User key life time should be a number';
41-
$string['createuser'] = 'Create user?';
42-
$string['createuser_desc'] = 'If enabled, a new user will be created if fail to find one in LMS.';
43-
$string['updateuser'] = 'Update user?';
44-
$string['updateuser_desc'] = 'If enabled, users will be updated with the properties supplied when the webservice is called.';
42+
$string['mappingfield'] = 'Mapping field';
43+
$string['mappingfield_desc'] = 'This user field will be used to find relevant user in the LMS.';
44+
$string['noip'] = 'Unable to fetch IP address of client.';
45+
$string['pluginisdisabled'] = 'The userkey authentication plugin is disabled.';
46+
$string['pluginname'] = 'User key authentication';
47+
$string['privacy:metadata'] = 'User key authentication plugin does not store any personal data.';
48+
$string['redirecterrordetected'] = 'Unsupported redirect to {$a} detected, execution terminated.';
4549
$string['redirecturl'] = 'Logout redirect URL';
4650
$string['redirecturl_desc'] = 'Optionally you can redirect users to this URL after they logged out from LMS.';
47-
$string['incorrectredirecturl'] = 'You should provide valid URL';
48-
$string['incorrectssourl'] = 'You should provide valid URL';
49-
$string['userkey:generatekey'] = 'Generate login user key';
50-
$string['pluginisdisabled'] = 'The userkey authentication plugin is disabled.';
5151
$string['ssourl'] = 'URL of SSO host';
5252
$string['ssourl_desc'] = 'URL of the SSO host to redirect users to. If defined users will be redirected here on login instead of the Moodle Login page';
53-
$string['redirecterrordetected'] = 'Unsupported redirect to {$a} detected, execution terminated.';
54-
$string['noip'] = 'Unable to fetch IP address of client.';
55-
$string['privacy:metadata'] = 'User key authentication plugin does not store any personal data.';
56-
$string['incorrectlogout'] = 'Incorrect logout request';
53+
$string['updateuser'] = 'Update user?';
54+
$string['updateuser_desc'] = 'If enabled, users will be updated with the properties supplied when the webservice is called.';
55+
$string['userkey:generatekey'] = 'Generate login user key';

0 commit comments

Comments
 (0)