From 7f264a85dac575ba769194fbc35f276f7a6b6c39 Mon Sep 17 00:00:00 2001 From: Daniel Thee Roperto Date: Mon, 14 Nov 2016 19:20:46 +1100 Subject: [PATCH] Code cleanup to meet code standards. --- classes/local/outagelib.php | 20 +++++++++---------- file.php | 9 +++++++-- tests/phpunit/local/cli/cli_testcase.php | 2 +- .../fixtures/subdir/withurls-subdir.css | 2 ++ .../maintenance_static_page_test.php | 3 ++- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/classes/local/outagelib.php b/classes/local/outagelib.php index 65b70c3..408743c 100644 --- a/classes/local/outagelib.php +++ b/classes/local/outagelib.php @@ -71,16 +71,6 @@ class outagelib { return; } - // Check if warning bar should be hidden. - if (optional_param('auth_outage_hide_warning', false, PARAM_BOOL)) { - return; - } - - // Used to test the try block in case of errors. - if (PHPUNIT_TEST && optional_param('auth_outage_break_code', false, PARAM_INT)) { - (new stdClass())->invalidfield; - } - // Check for a previewing outage, then for an active outage. $previewid = optional_param('auth_outage_preview', null, PARAM_INT); $time = time(); @@ -200,6 +190,16 @@ class outagelib { return false; } + // Check if warning bar should be hidden. + if (optional_param('auth_outage_hide_warning', false, PARAM_BOOL)) { + return false; + } + + // Used to test the try block in case of errors. + if (PHPUNIT_TEST && optional_param('auth_outage_break_code', false, PARAM_INT)) { + (new stdClass())->invalidfield; // Triggers an exception. + } + // Nothing preventing the injection. return true; } diff --git a/file.php b/file.php index 799566c..8884d37 100644 --- a/file.php +++ b/file.php @@ -54,6 +54,11 @@ header('Pragma: '); header('Cache-Control: public, max-age='.$lifetime); header('Accept-Ranges: none'); + +/** + * Callback used in bootstrap. + * @SupressWarnings(PHPMD) + */ function auth_outage_bootstrap_callback() { global $CFG; @@ -72,8 +77,8 @@ function auth_outage_bootstrap_callback() { } readfile($file); - die(); -}; + exit(0); +} require_once(__DIR__.'/../../config.php'); diff --git a/tests/phpunit/local/cli/cli_testcase.php b/tests/phpunit/local/cli/cli_testcase.php index 32fec0e..6a2914c 100644 --- a/tests/phpunit/local/cli/cli_testcase.php +++ b/tests/phpunit/local/cli/cli_testcase.php @@ -44,7 +44,7 @@ abstract class auth_outage_cli_testcase extends auth_outage_base_testcase { public function setUp() { global $CFG; - // PHPUnit does not load config.php + // PHPUnit does not load config.php file. $CFG->auth_outage_bootstrap_loaded = true; // Enable auth plugins. diff --git a/tests/phpunit/local/controllers/fixtures/subdir/withurls-subdir.css b/tests/phpunit/local/controllers/fixtures/subdir/withurls-subdir.css index 3e9c1a8..68bee4c 100644 --- a/tests/phpunit/local/controllers/fixtures/subdir/withurls-subdir.css +++ b/tests/phpunit/local/controllers/fixtures/subdir/withurls-subdir.css @@ -1 +1,3 @@ +/* csslint ignore:start */ @import url(../simple.css); +/* csslint ignore:end */ diff --git a/tests/phpunit/local/controllers/maintenance_static_page_test.php b/tests/phpunit/local/controllers/maintenance_static_page_test.php index f1babc2..d0a630c 100644 --- a/tests/phpunit/local/controllers/maintenance_static_page_test.php +++ b/tests/phpunit/local/controllers/maintenance_static_page_test.php @@ -38,6 +38,7 @@ require_once(__DIR__.'/../../base_testcase.php'); * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @SuppressWarnings(public) Allow as many methods as needed. + * @SuppressWarnings(methods) Allow as many methods as needed. */ class maintenance_static_page_test extends auth_outage_base_testcase { public function test_templatefile() { @@ -130,7 +131,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase { $page->generate(); // Check for css file. - self::assertFileExists($page->get_io()->get_resources_folder().'/4ea71b83ab326a15d0d784b34fcda702b6a7427d.dGV4dC9wbGFpbg'); + self::assertFileExists($page->get_io()->get_resources_folder().'/beb44281e23b9d872056bf0230cea34535e8cdea.dGV4dC9wbGFpbg'); // Check for file referenced in url(..) of css. self::assertFileExists($page->get_io()->get_resources_folder().'/a02a8a442fa82d5205ffb24722d9df7f35161f56.dGV4dC9wbGFpbg');