Skip to content

Commit

Permalink
ci: cleanup to match coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhilton authored and brendanheywood committed Nov 17, 2024
1 parent 53c6a5c commit da109a3
Show file tree
Hide file tree
Showing 28 changed files with 50 additions and 37 deletions.
2 changes: 1 addition & 1 deletion aborttest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
$PAGE->set_context($syscontext);
$PAGE->set_pagelayout('standard');
$PAGE->set_cacheable(false);
$url->params(array('stage' => 2));
$url->params(['stage' => 2]);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('testabort', 'tool_heartbeat'));

Expand Down
8 changes: 4 additions & 4 deletions adminloginchecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
define('NO_UPGRADE_CHECK', true);
// @codingStandardsIgnoreEnd

$options = array(
$options = [
'help' => false,
'critthresh' => 60 * 60 * 24 * 3,
'warnthresh' => 60 * 60 * 24 * 7,
);
];

if (isset($argv)) {
// If run from the CLI.
Expand All @@ -51,9 +51,9 @@
require_once($CFG->libdir . '/clilib.php');

list($options, $unrecognized) = cli_get_params($options,
array(
[
'h' => 'help',
)
]
);

if ($unrecognized) {
Expand Down
2 changes: 1 addition & 1 deletion buffercheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

$files = [
$CFG->dirroot . '/backup/backup.php',
$CFG->dirroot . '/backup/restore.php'
$CFG->dirroot . '/backup/restore.php',
];

foreach ($files as $file) {
Expand Down
3 changes: 2 additions & 1 deletion classes/check/authcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Auth method health check.
*
Expand Down Expand Up @@ -56,7 +57,7 @@ public function get_action_link(): ?\action_link {
*
* @return result
*/
public function get_result() : result {
public function get_result(): result {
global $DB;

// Value must be raw DB value. We will see it here before in settings cache.
Expand Down
2 changes: 1 addition & 1 deletion classes/check/cachecheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class cachecheck extends check {
*
* @return result
*/
public function get_result() : result {
public function get_result(): result {
$results = $this->check('web');
$results += $this->check('cron');

Expand Down
2 changes: 1 addition & 1 deletion classes/check/dirsizes.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class dirsizes extends check {
*
* @return result
*/
public function get_result() : result {
public function get_result(): result {
global $CFG;

$sizedataroot = get_directory_size($CFG->dataroot);
Expand Down
3 changes: 2 additions & 1 deletion classes/check/dnscheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* DNS security check.
*
Expand Down Expand Up @@ -40,7 +41,7 @@ class dnscheck extends check {
*
* @return result
*/
public function get_result() : result {
public function get_result(): result {
global $DB, $CFG;

$url = new \moodle_url($CFG->wwwroot);
Expand Down
2 changes: 1 addition & 1 deletion classes/check/failingtaskcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function get_action_link(): ?\action_link {
* Return result
* @return result
*/
public function get_result() : result {
public function get_result(): result {
global $DB;

// Return OK if no task errors.
Expand Down
3 changes: 2 additions & 1 deletion classes/check/rangerequestcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Range request performance check.
*
Expand Down Expand Up @@ -47,7 +48,7 @@ class rangerequestcheck extends check {
*
* @return result
*/
public function get_result() : result {
public function get_result(): result {

$url = new \moodle_url('/pluginfile.php/1/tool_heartbeat/test');

Expand Down
1 change: 1 addition & 0 deletions classes/check/tasklatencycheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Individual cron task latency monitoring check check.
*
Expand Down
4 changes: 2 additions & 2 deletions classes/checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,15 @@ public static function apply_configuration_settings($ref, result $result): resul
return $result;
}
// Get a map of result string to integers representing their "order level".
$map = checker::RESULT_ORDER;
$map = self::RESULT_ORDER;
// Get the order value of each status.
$maxint = $map[$max];
$realint = $map[$status];
// Determine the lowest ordered status of the two.
$finalint = min($maxint, $realint);
// Flip the array to be integer => string constant and return the allowed
// final status.
$status = array_flip($map)[$finalint];
$status = array_flip($map)[$finalint];
return new result($status, $result->get_summary(), $result->get_details());
}
/**
Expand Down
1 change: 1 addition & 0 deletions classes/form/override_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Override form
*
Expand Down
2 changes: 1 addition & 1 deletion classes/object/override.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
*
* Heartbeat override
Expand Down Expand Up @@ -44,7 +45,6 @@ class override extends Persistent {
* @param int $id If set, this is the id of an existing record, used to load the data.
* @param \stdClass $record If set will be passed to {@link self::from_record()}.
*/

public function __construct(int $id = 0, \stdClass $record = null) {
$this->set_default_status();
$this->set_default_expiry();
Expand Down
1 change: 1 addition & 0 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Privacy Subsystem implementation for tool_heartbeat.
*
Expand Down
1 change: 0 additions & 1 deletion classes/task/cachecheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.


namespace tool_heartbeat\task;

/**
Expand Down
8 changes: 4 additions & 4 deletions cli/testupload.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@
require_once($CFG->libdir.'/clilib.php');

list($options, $unrecognized) = cli_get_params(
array(
[
'help' => false,
'size' => 1024 * 10,
'chunks' => 100,
'delay' => 0,
'wwwroot' => $CFG->wwwroot,
'verbose' => 0,
),
array(
],
[
'h' => 'help',
's' => 'size',
'c' => 'chunks',
'd' => 'delay',
'w' => 'wwwroot',
'v' => 'verbose',
)
]
);

if ($unrecognized) {
Expand Down
1 change: 1 addition & 0 deletions db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Cache split check.
*
Expand Down
2 changes: 2 additions & 0 deletions db/tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Tool heartbeat
*
* @author Brendan Heywood <brendan@catalyst-au.net>
* @copyright Catalyst IT 2023
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package tool_heartbeat
*/

defined('MOODLE_INTERNAL') || die();
Expand Down
1 change: 1 addition & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* DB upgrade script.
*
Expand Down
2 changes: 2 additions & 0 deletions errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
echo $OUTPUT->header();
echo $OUTPUT->heading('Tests for all errors in the whole stack');

// @codingStandardsIgnoreStart
?>
<h3>Moodle high level errors</h3>
<p>These should all use the moodle theme</p>
Expand Down Expand Up @@ -74,6 +75,7 @@
<li>A 502 Bad Gateway, proxy cannot connect at all (how to test?)</li>

<?php
// @codingStandardsIgnoreEnd

echo $OUTPUT->footer();

2 changes: 2 additions & 0 deletions errors/phpwarnings.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
trigger_error("This is a notice", E_USER_NOTICE);
trigger_error("This is a warning", E_USER_WARNING);

// @codingStandardsIgnoreStart
error_log("This is an error_log");
// @codingStandardsIgnoreEnd
file_put_contents("php://stderr", "This writing to php://stderr");

2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function failed($reason) {
}

if ($fullcheck || $checksession) {
$c = new curl(array('cache' => false, 'cookie' => true));
$c = new curl(['cache' => false, 'cookie' => true]);
$response = $c->get(new moodle_url('/admin/tool/heartbeat/sessionone.php'));
if ($sessioncheck = json_decode($response)) {
if ($sessioncheck->success == 'pass') {
Expand Down
3 changes: 2 additions & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Callback point.
*
Expand Down Expand Up @@ -85,7 +86,7 @@ function tool_heartbeat_security_checks() {
* @param array $options More options
* @return bool Returns false if we don't find a file.
*/
function tool_heartbeat_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
function tool_heartbeat_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) {
global $CFG;

// README is just safe content we know exist. Used in the range request check.
Expand Down
10 changes: 5 additions & 5 deletions loginchecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
define('NO_UPGRADE_CHECK', true);
// @codingStandardsIgnoreEnd

$options = array(
$options = [
'help' => false,
'critthresh' => 500,
'warnthresh' => 10,
'logtime' => 5,
);
];

if (isset($argv)) {
// If run from the CLI.
Expand All @@ -52,9 +52,9 @@
require_once($CFG->libdir . '/clilib.php');

list($options, $unrecognized) = cli_get_params($options,
array(
[
'h' => 'help',
)
]
);

if ($unrecognized) {
Expand Down Expand Up @@ -106,7 +106,7 @@
WHERE target = 'user_login'
AND timecreated > :checktime";

$tablequery = $DB->get_record_sql($sqlstring, array('checktime' => $checktime));
$tablequery = $DB->get_record_sql($sqlstring, ['checktime' => $checktime]);

$count = $tablequery->logincount;

Expand Down
5 changes: 2 additions & 3 deletions sessionone.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.


/**
* Set a random integer in session and redirect to check if persists.
*
Expand All @@ -35,10 +34,10 @@

$SESSION->testnumber = $testnumber;

$params = array(
$params = [
'testnumber' => $testnumber,
'reqtime' => $testtimemicro,
'host' => $hostname);
'host' => $hostname];
$url = new moodle_url('/admin/tool/heartbeat/sessiontwo.php', $params);

redirect($url);
6 changes: 3 additions & 3 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@

if (!during_initial_install()) {

$options = array(
$options = [
'' => new lang_string('normal', 'tool_heartbeat'),
'warn' => new lang_string('testwarning', 'tool_heartbeat'),
'error' => new lang_string('testerror', 'tool_heartbeat'),
);
];
$settings->add(new admin_setting_configselect('tool_heartbeat/testing',
new lang_string('testing', 'tool_heartbeat'),
new lang_string('testingdesc', 'tool_heartbeat'),
Expand Down Expand Up @@ -94,7 +94,7 @@
$opts = [
'critical' => 'CRITICAL',
'criticalbusiness' => get_string('error_critical_business', 'tool_heartbeat'),
'warning' => 'WARNING'
'warning' => 'WARNING',
];
$time = new \DateTime('now', core_date::get_server_timezone_object());
$settings->add(new admin_setting_configselect('tool_heartbeat/errorcritical',
Expand Down
4 changes: 2 additions & 2 deletions tests/check/tasklatencycheck_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function test_start_time_drift() {
// Now set a lock on the task. This should prevent critical.
$CFG->lock_factory = \tool_lockstats\proxy_lock_factory::class;
$DB->insert_record('tool_lockstats_locks', [
'resourcekey' => '\\logstore_standard\\task\\cleanup_task'
'resourcekey' => '\\logstore_standard\\task\\cleanup_task',
]);
$result = $check->get_result();
$this->assertEquals(result::OK, $result->get_status());
Expand Down Expand Up @@ -120,7 +120,7 @@ public function test_task_not_run() {
// Now set a lock on the task. This should prevent critical.
$CFG->lock_factory = \tool_lockstats\proxy_lock_factory::class;
$DB->insert_record('tool_lockstats_locks', [
'resourcekey' => '\\logstore_standard\\task\\cleanup_task'
'resourcekey' => '\\logstore_standard\\task\\cleanup_task',
]);
$result = $check->get_result();
$this->assertEquals(result::OK, $result->get_status());
Expand Down
Loading

0 comments on commit da109a3

Please sign in to comment.