diff --git a/auth.php b/auth.php index b8838f9..0d84e2c 100644 --- a/auth.php +++ b/auth.php @@ -46,7 +46,7 @@ class auth_plugin_outage extends auth_plugin_base * Do not authenticate users. * @return bool False */ - public function user_login($username, $password) { + public function user_login() { return false; } } diff --git a/classes/forms/outage/delete.php b/classes/forms/outage/delete.php index 90976ca..26139fa 100644 --- a/classes/forms/outage/delete.php +++ b/classes/forms/outage/delete.php @@ -53,7 +53,6 @@ class delete extends \moodleform { */ public function validation($data, $files) { $errors = parent::validation($data, $files); - $mform = $this->_form; return $errors; } diff --git a/classes/forms/outage/edit.php b/classes/forms/outage/edit.php index bed0be6..9c511e4 100644 --- a/classes/forms/outage/edit.php +++ b/classes/forms/outage/edit.php @@ -64,7 +64,6 @@ class edit extends \moodleform { */ public function validation($data, $files) { $errors = parent::validation($data, $files); - $mform = $this->_form; return $errors; } diff --git a/classes/outagelib.php b/classes/outagelib.php index d8e3543..909ee8b 100644 --- a/classes/outagelib.php +++ b/classes/outagelib.php @@ -47,9 +47,8 @@ class outagelib * * @param $data mixed An object or array. * @param $obj object Destination object to write the properties. - * @param $strict bool All data fields must be used in the destination object or an exception will be thrown. */ - public static function data2object($data, $obj, $strict = false) { + public static function data2object($data, $obj) { if (is_object($data)) { $data = get_object_vars($data); } @@ -59,16 +58,9 @@ class outagelib if (!is_object($obj)) { throw new \InvalidArgumentException('$obj must be an object.'); } - if (!is_bool($strict)) { - throw new \InvalidArgumentException('$strict must be a bool.'); - } foreach ($data as $k => $v) { - if (!property_exists($obj, $k)) { - if ($strict) { - throw new \InvalidArgumentException('$obj does not have a property called ' . $k); - } - } else { + if (property_exists($obj, $k)) { if (method_exists($obj, $k)) { throw new \InvalidArgumentException('$obj has a method called ' . $k); } diff --git a/renderer.php b/renderer.php index 772ec5c..f95945d 100644 --- a/renderer.php +++ b/renderer.php @@ -32,7 +32,9 @@ if (!defined('MOODLE_INTERNAL')) { class auth_outage_renderer extends plugin_renderer_base { public function rendersubtitle($subtitlekey) { - if (!is_string($subtitlekey)) throw new \InvalidArgumentException('$subtitle is not a string.'); + if (!is_string($subtitlekey)) { + throw new \InvalidArgumentException('$subtitle is not a string.'); + } return html_writer::tag('h2', get_string($subtitlekey, 'auth_outage')); } diff --git a/tests/outage_test.php b/tests/outage_test.php index fc6485c..b62097d 100644 --- a/tests/outage_test.php +++ b/tests/outage_test.php @@ -35,7 +35,7 @@ class outage_test extends basic_testcase // Very important, this should never change. self::assertNull($outage->id, 'New empty outage can never have an id set.'); // Ensure all other fields are also null. - foreach ($outage as $k=>$v) { + foreach ($outage as $v) { self::assertNull($v); } } diff --git a/tests/outagelib_test.php b/tests/outagelib_test.php index fbe0e74..ce4c5a1 100644 --- a/tests/outagelib_test.php +++ b/tests/outagelib_test.php @@ -31,44 +31,22 @@ defined('MOODLE_INTERNAL') || die(); class outagelib_test extends basic_testcase { public function test_data2object() { - // Using object data, no new fields, not strict. + // Using object data, no new fields. $obj = new stdClass(); $obj->foo = 'bar'; $obj->number = 42; $data = new stdClass(); $data->foo = 'not bar'; - outagelib::data2object($data, $obj, false); + outagelib::data2object($data, $obj); self::assertEquals(get_object_vars($obj), ['foo' => 'not bar', 'number' => 42], 'Invalid result.'); self::assertEquals(get_object_vars($data), ['foo' => 'not bar'], 'Data should not change.'); - // Using array data, with new fields, not strict. + // Using array data, with new fields. $obj = new stdClass(); $obj->foo = 'bar'; $obj->number = 42; $data = ['foo' => 'foobar', 'flag' => false]; - outagelib::data2object($data, $obj, false); + outagelib::data2object($data, $obj); self::assertEquals(get_object_vars($obj), ['foo' => 'foobar', 'number' => 42], 'Invalid result.'); - - // Using object data, no new fields, strict. - $obj = new stdClass(); - $obj->foo = 'bar'; - $obj->number = 42; - $data = new stdClass(); - $data->foo = 'not bar'; - outagelib::data2object($data, $obj, true); - self::assertEquals(get_object_vars($obj), ['foo' => 'not bar', 'number' => 42], 'Invalid result.'); - self::assertEquals(get_object_vars($data), ['foo' => 'not bar'], 'Data should not change.'); - - // Using array data, with new fields, strict. - $obj = new stdClass(); - $obj->foo = 'bar'; - $obj->number = 42; - $data = ['foo' => 'foobar', 'flag' => false]; - try { - outagelib::data2object($data, $obj, true); - $this->fail('Exception was expected.'); - } - catch (InvalidArgumentException $e){ - } } }