From bbf60b14129653b94c768fa2c5d916d38f7a0d1e Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 11 Jan 2019 17:12:37 +0100 Subject: [PATCH] MDL-57898 core_customfield: coding style fixes --- course/classes/customfield/course_handler.php | 10 +++---- course/classes/list_element.php | 4 +-- course/externallib.php | 9 ++++-- course/tests/externallib_test.php | 2 +- customfield/classes/api.php | 12 ++++---- customfield/classes/category.php | 2 +- customfield/classes/category_controller.php | 6 ++-- customfield/classes/data.php | 2 +- customfield/classes/data_controller.php | 14 ++++----- .../classes/event/category_created.php | 2 +- .../classes/event/category_deleted.php | 2 +- .../classes/event/category_updated.php | 2 +- customfield/classes/event/field_created.php | 2 +- customfield/classes/event/field_deleted.php | 2 +- customfield/classes/event/field_updated.php | 2 +- customfield/classes/field.php | 4 +-- customfield/classes/field_controller.php | 12 ++++---- customfield/classes/handler.php | 30 +++++++++---------- customfield/classes/output/field_data.php | 8 ++--- customfield/classes/privacy/provider.php | 2 +- .../checkbox/classes/field_controller.php | 2 +- .../field/checkbox/tests/plugin_test.php | 2 +- .../field/date/classes/data_controller.php | 2 +- .../field/date/classes/privacy/provider.php | 2 +- customfield/field/date/tests/plugin_test.php | 2 +- .../field/select/classes/data_controller.php | 2 +- .../field/select/classes/field_controller.php | 4 +-- .../field/select/tests/plugin_test.php | 2 +- .../field/text/classes/data_controller.php | 2 +- .../field/text/classes/field_controller.php | 2 +- customfield/field/text/tests/plugin_test.php | 2 +- .../textarea/classes/data_controller.php | 2 +- .../textarea/classes/field_controller.php | 2 +- .../field/textarea/tests/plugin_test.php | 2 +- customfield/templates/list.mustache | 4 +-- customfield/tests/api_test.php | 2 +- .../tests/category_controller_test.php | 2 +- customfield/tests/data_controller_test.php | 2 +- customfield/tests/field_controller_test.php | 2 +- customfield/tests/generator/lib.php | 4 +-- customfield/tests/generator_test.php | 2 +- customfield/tests/privacy_test.php | 2 +- lib/adminlib.php | 4 +++ lib/classes/plugininfo/customfield.php | 5 +++- lib/testing/generator/data_generator.php | 6 ++-- 45 files changed, 102 insertions(+), 92 deletions(-) diff --git a/course/classes/customfield/course_handler.php b/course/classes/customfield/course_handler.php index cc94d2ea9dc..329e763aca7 100644 --- a/course/classes/customfield/course_handler.php +++ b/course/classes/customfield/course_handler.php @@ -104,7 +104,7 @@ class course_handler extends \core_customfield\handler { * @param int $instanceid id of the course to test edit permission * @return bool true if the current can edit custom fields, false otherwise */ - public function can_view(field_controller $field, int $instanceid): bool { + public function can_view(field_controller $field, int $instanceid) : bool { $visibility = $field->get_configdata_property('visibility'); if ($visibility == self::NOTVISIBLE) { return false; @@ -146,7 +146,7 @@ class course_handler extends \core_customfield\handler { * * @return \context the context for configuration */ - public function get_configuration_context(): \context { + public function get_configuration_context() : \context { return \context_system::instance(); } @@ -155,7 +155,7 @@ class course_handler extends \core_customfield\handler { * * @return \moodle_url The URL to configure custom fields for this component */ - public function get_configuration_url(): \moodle_url { + public function get_configuration_url() : \moodle_url { return new \moodle_url('/course/customfield.php'); } @@ -165,7 +165,7 @@ class course_handler extends \core_customfield\handler { * @param int $instanceid id of the record to get the context for * @return \context the context for the given record */ - public function get_instance_context(int $instanceid = 0): \context { + public function get_instance_context(int $instanceid = 0) : \context { if ($instanceid > 0) { return \context_course::instance($instanceid); } else { @@ -230,7 +230,7 @@ class course_handler extends \core_customfield\handler { * @param field_controller $field * @return string page heading */ - public function setup_edit_page(field_controller $field): string { + public function setup_edit_page(field_controller $field) : string { global $CFG, $PAGE; require_once($CFG->libdir.'/adminlib.php'); diff --git a/course/classes/list_element.php b/course/classes/list_element.php index 8cd43c26877..7d5eab4ce5a 100644 --- a/course/classes/list_element.php +++ b/course/classes/list_element.php @@ -205,7 +205,7 @@ class core_course_list_element implements IteratorAggregate { * * @return \core_customfield\data_controller[] */ - public function get_custom_fields(): array { + public function get_custom_fields() : array { if (!isset($this->record->customfields)) { $this->record->customfields = \core_course\customfield\course_handler::create()->get_instance_data($this->id); } @@ -217,7 +217,7 @@ class core_course_list_element implements IteratorAggregate { * * @return bool */ - public function has_custom_fields(): bool { + public function has_custom_fields() : bool { $customfields = $this->get_custom_fields(); return !empty($customfields); } diff --git a/course/externallib.php b/course/externallib.php index 0eb164cef8e..f30b41a6d20 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -682,7 +682,8 @@ class core_course_external extends external_api { new external_single_structure( ['name' => new external_value(PARAM_TEXT, 'The name of the custom field'), 'shortname' => new external_value(PARAM_ALPHANUMEXT, 'The shortname of the custom field'), - 'type' => new external_value(PARAM_COMPONENT, 'The type of the custom field - text, checkbox...'), + 'type' => new external_value(PARAM_COMPONENT, + 'The type of the custom field - text, checkbox...'), 'value' => new external_value(PARAM_RAW, 'The value of the custom field')] ), 'Custom fields and associated values', VALUE_OPTIONAL), ), 'course' @@ -2548,8 +2549,10 @@ class core_course_external extends external_api { new external_single_structure( array( 'name' => new external_value(PARAM_RAW, 'The name of the custom field'), - 'shortname' => new external_value(PARAM_RAW, 'The shortname of the custom field - to be able to build the field class in the code'), - 'type' => new external_value(PARAM_ALPHANUMEXT, 'The type of the custom field - text field, checkbox...'), + 'shortname' => new external_value(PARAM_RAW, + 'The shortname of the custom field - to be able to build the field class in the code'), + 'type' => new external_value(PARAM_ALPHANUMEXT, + 'The type of the custom field - text field, checkbox...'), 'value' => new external_value(PARAM_RAW, 'The value of the custom field'), ) ), 'Custom fields', VALUE_OPTIONAL), diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php index d4b6881e4bc..9198c2a7383 100644 --- a/course/tests/externallib_test.php +++ b/course/tests/externallib_test.php @@ -409,7 +409,7 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { // Enable course themes. set_config('allowcoursethemes', 1); - // Custom fields + // Custom fields. $fieldcategory = self::getDataGenerator()->create_custom_field_category(['name' => 'Other fields']); $customfield = ['shortname' => 'test', 'name' => 'Custom field', 'type' => 'text', diff --git a/customfield/classes/api.php b/customfield/classes/api.php index 52ddc64fdad..440ba611830 100644 --- a/customfield/classes/api.php +++ b/customfield/classes/api.php @@ -54,7 +54,7 @@ class api { * If ($adddefaults): All fieldids are present, some data_controller objects may have 'id', some not. * If (!$adddefaults): Only fieldids with data are present, all data_controller objects have 'id'. */ - public static function get_instance_fields_data(array $fields, int $instanceid, bool $adddefaults = true): array { + public static function get_instance_fields_data(array $fields, int $instanceid, bool $adddefaults = true) : array { return self::get_instances_fields_data($fields, [$instanceid], $adddefaults)[$instanceid]; } @@ -69,7 +69,7 @@ class api { * If (!$adddefaults): All instanceids are present but only fieldids with data are present, all * data_controller objects have 'id'. */ - public static function get_instances_fields_data(array $fields, array $instanceids, bool $adddefaults = true): array { + public static function get_instances_fields_data(array $fields, array $instanceids, bool $adddefaults = true) : array { global $DB; // Create the results array where instances and fields order is the same as in the input arrays. @@ -230,7 +230,7 @@ class api { * * @param field_controller $field */ - public static function delete_field_configuration(field_controller $field): bool { + public static function delete_field_configuration(field_controller $field) : bool { $event = field_deleted::create_from_object($field); get_file_storage()->delete_area_files($field->get_handler()->get_configuration_context()->id, 'core_customfield', 'description', $field->get('id')); @@ -318,7 +318,7 @@ class api { * @param category_controller $category * @return bool */ - public static function delete_category(category_controller $category): bool { + public static function delete_category(category_controller $category) : bool { $event = category_deleted::create_from_object($category); // Delete all fields. @@ -339,7 +339,7 @@ class api { * @param int $itemid * @return category_controller[] */ - public static function get_categories_with_fields(string $component, string $area, int $itemid): array { + public static function get_categories_with_fields(string $component, string $area, int $itemid) : array { global $DB; $categories = []; @@ -397,7 +397,7 @@ class api { * @param field_controller $field * @return \stdClass */ - public static function prepare_field_for_config_form(field_controller $field): \stdClass { + public static function prepare_field_for_config_form(field_controller $field) : \stdClass { if ($field->get('id')) { $formdata = $field->to_record(); $formdata->configdata = $field->get('configdata'); diff --git a/customfield/classes/category.php b/customfield/classes/category.php index 0a7dff99851..dd89f556bad 100644 --- a/customfield/classes/category.php +++ b/customfield/classes/category.php @@ -46,7 +46,7 @@ class category extends persistent { * * @return array */ - protected static function define_properties(): array { + protected static function define_properties() : array { return array( 'name' => [ 'type' => PARAM_TEXT, diff --git a/customfield/classes/category_controller.php b/customfield/classes/category_controller.php index ee2e3fc6a62..601b10616ab 100644 --- a/customfield/classes/category_controller.php +++ b/customfield/classes/category_controller.php @@ -77,7 +77,7 @@ class category_controller { * @throws \moodle_exception * @throws \coding_exception */ - public static function create(int $id, \stdClass $record = null, handler $handler = null): category_controller { + public static function create(int $id, \stdClass $record = null, handler $handler = null) : category_controller { global $DB; if ($id && $record) { // This warning really should be in persistent as well. @@ -180,7 +180,7 @@ class category_controller { * * @return handler */ - public function get_handler(): handler { + public function get_handler() : handler { if ($this->handler === null) { $this->handler = handler::get_handler($this->get('component'), $this->get('area'), $this->get('itemid')); } @@ -224,7 +224,7 @@ class category_controller { * * @return string */ - public function get_formatted_name(): string { + public function get_formatted_name() : string { $context = $this->get_handler()->get_configuration_context(); return format_string($this->get('name'), true, ['context' => $context]); } diff --git a/customfield/classes/data.php b/customfield/classes/data.php index 855194065a1..fc23a82dc13 100644 --- a/customfield/classes/data.php +++ b/customfield/classes/data.php @@ -47,7 +47,7 @@ class data extends persistent { * * @return array */ - protected static function define_properties(): array { + protected static function define_properties() : array { return array( 'fieldid' => [ 'type' => PARAM_INT, diff --git a/customfield/classes/data_controller.php b/customfield/classes/data_controller.php index dd13c4dc6e5..8ec6ac639b1 100644 --- a/customfield/classes/data_controller.php +++ b/customfield/classes/data_controller.php @@ -82,7 +82,7 @@ abstract class data_controller { * @throws \coding_exception * @throws \moodle_exception */ - public static function create(int $id, \stdClass $record = null, field_controller $field = null): data_controller { + public static function create(int $id, \stdClass $record = null, field_controller $field = null) : data_controller { global $DB; if ($id && $record) { // This warning really should be in persistent as well. @@ -122,7 +122,7 @@ abstract class data_controller { * * @return string */ - protected function get_form_element_name(): string { + protected function get_form_element_name() : string { return 'customfield_' . $this->get_field()->get('shortname'); } @@ -185,7 +185,7 @@ abstract class data_controller { * * @return field_controller */ - public function get_field(): field_controller { + public function get_field() : field_controller { return $this->field; } @@ -223,7 +223,7 @@ abstract class data_controller { * @param mixed $value * @return bool */ - protected function is_empty($value): bool { + protected function is_empty($value) : bool { if ($this->datafield() === 'value' || $this->datafield() === 'charvalue' || $this->datafield() === 'shortcharvalue') { return '' . $value === ''; } @@ -236,7 +236,7 @@ abstract class data_controller { * @param mixed $value * @return bool */ - protected function is_unique($value): bool { + protected function is_unique($value) : bool { global $DB; $datafield = $this->datafield(); $where = "fieldid = ? AND {$datafield} = ?"; @@ -255,7 +255,7 @@ abstract class data_controller { * @param array $files * @return array array of errors */ - public function instance_form_validation(array $data, array $files): array { + public function instance_form_validation(array $data, array $files) : array { $errors = []; $elementname = $this->get_form_element_name(); if ($this->get_field()->get_configdata_property('uniquevalues') == 1) { @@ -281,7 +281,7 @@ abstract class data_controller { * * @return string */ - public function display(): string { + public function display() : string { global $PAGE; $output = $PAGE->get_renderer('core_customfield'); return $output->render(new field_data($this)); diff --git a/customfield/classes/event/category_created.php b/customfield/classes/event/category_created.php index b5234e03f3f..5a83d290f82 100644 --- a/customfield/classes/event/category_created.php +++ b/customfield/classes/event/category_created.php @@ -53,7 +53,7 @@ class category_created extends \core\event\base { * @param category_controller $category * @return category_created */ - public static function create_from_object(category_controller $category): category_created { + public static function create_from_object(category_controller $category) : category_created { $eventparams = [ 'objectid' => $category->get('id'), 'context' => $category->get_handler()->get_configuration_context(), diff --git a/customfield/classes/event/category_deleted.php b/customfield/classes/event/category_deleted.php index ce6064db846..1e08f258cb5 100644 --- a/customfield/classes/event/category_deleted.php +++ b/customfield/classes/event/category_deleted.php @@ -53,7 +53,7 @@ class category_deleted extends \core\event\base { * @param category_controller $category * @return category_deleted */ - public static function create_from_object(category_controller $category): category_deleted { + public static function create_from_object(category_controller $category) : category_deleted { $eventparams = [ 'objectid' => $category->get('id'), 'context' => $category->get_handler()->get_configuration_context(), diff --git a/customfield/classes/event/category_updated.php b/customfield/classes/event/category_updated.php index 2006c12344a..ba7bc2c1d6b 100644 --- a/customfield/classes/event/category_updated.php +++ b/customfield/classes/event/category_updated.php @@ -53,7 +53,7 @@ class category_updated extends \core\event\base { * @param category_controller $category * @return category_updated */ - public static function create_from_object(category_controller $category): category_updated { + public static function create_from_object(category_controller $category) : category_updated { $eventparams = [ 'objectid' => $category->get('id'), 'context' => $category->get_handler()->get_configuration_context(), diff --git a/customfield/classes/event/field_created.php b/customfield/classes/event/field_created.php index cdb016787dd..20d4f556532 100644 --- a/customfield/classes/event/field_created.php +++ b/customfield/classes/event/field_created.php @@ -53,7 +53,7 @@ class field_created extends \core\event\base { * @param field_controller $field * @return field_created */ - public static function create_from_object(field_controller $field): field_created { + public static function create_from_object(field_controller $field) : field_created { $eventparams = [ 'objectid' => $field->get('id'), 'context' => $field->get_handler()->get_configuration_context(), diff --git a/customfield/classes/event/field_deleted.php b/customfield/classes/event/field_deleted.php index f3c935f21fa..586705d21cd 100644 --- a/customfield/classes/event/field_deleted.php +++ b/customfield/classes/event/field_deleted.php @@ -53,7 +53,7 @@ class field_deleted extends \core\event\base { * @param field_controller $field * @return field_deleted */ - public static function create_from_object(field_controller $field): field_deleted { + public static function create_from_object(field_controller $field) : field_deleted { $eventparams = [ 'objectid' => $field->get('id'), 'context' => $field->get_handler()->get_configuration_context(), diff --git a/customfield/classes/event/field_updated.php b/customfield/classes/event/field_updated.php index 02a17f2e605..619a4a4dad4 100644 --- a/customfield/classes/event/field_updated.php +++ b/customfield/classes/event/field_updated.php @@ -53,7 +53,7 @@ class field_updated extends \core\event\base { * @param field_controller $field * @return field_updated */ - public static function create_from_object(field_controller $field): field_updated { + public static function create_from_object(field_controller $field) : field_updated { $eventparams = [ 'objectid' => $field->get('id'), 'context' => $field->get_handler()->get_configuration_context(), diff --git a/customfield/classes/field.php b/customfield/classes/field.php index d30cf37b60d..1f7b7e1ec2c 100644 --- a/customfield/classes/field.php +++ b/customfield/classes/field.php @@ -47,7 +47,7 @@ class field extends persistent { * * @return array */ - protected static function define_properties(): array { + protected static function define_properties() : array { return array( 'name' => [ 'type' => PARAM_TEXT, @@ -91,7 +91,7 @@ class field extends persistent { * * @return array */ - protected function get_configdata(): array { + protected function get_configdata() : array { return json_decode($this->raw_get('configdata'), true) ?? array(); } } diff --git a/customfield/classes/field_controller.php b/customfield/classes/field_controller.php index f54026a4dd9..b9da5b93695 100644 --- a/customfield/classes/field_controller.php +++ b/customfield/classes/field_controller.php @@ -81,7 +81,7 @@ abstract class field_controller { * @throws \coding_exception * @throws \moodle_exception */ - public static function create(int $id, \stdClass $record = null, category_controller $category = null): field_controller { + public static function create(int $id, \stdClass $record = null, category_controller $category = null) : field_controller { global $DB; if ($id && $record) { // This warning really should be in persistent as well. @@ -132,7 +132,7 @@ abstract class field_controller { * @param array $files * @return array associative array of error messages */ - public function config_form_validation(array $data, $files = array()): array { + public function config_form_validation(array $data, $files = array()) : array { return array(); } @@ -167,7 +167,7 @@ abstract class field_controller { * * @return bool */ - public function delete(): bool { + public function delete() : bool { global $DB; $DB->delete_records('customfield_data', ['fieldid' => $this->get('id')]); return $this->field->delete(); @@ -196,7 +196,7 @@ abstract class field_controller { * * @return category_controller */ - public final function get_category(): category_controller { + public final function get_category() : category_controller { return $this->category; } @@ -219,7 +219,7 @@ abstract class field_controller { * * @return handler */ - public final function get_handler(): handler { + public final function get_handler() : handler { return $this->get_category()->get_handler(); } @@ -245,7 +245,7 @@ abstract class field_controller { * * @return string */ - public function get_formatted_name(): string { + public function get_formatted_name() : string { $context = $this->get_handler()->get_configuration_context(); return format_string($this->get('name'), true, ['context' => $context]); } diff --git a/customfield/classes/handler.php b/customfield/classes/handler.php index fe633f146f3..af25c2c1583 100644 --- a/customfield/classes/handler.php +++ b/customfield/classes/handler.php @@ -174,7 +174,7 @@ abstract class handler { * * @return bool */ - public function uses_categories(): bool { + public function uses_categories() : bool { return true; } @@ -184,7 +184,7 @@ abstract class handler { * @param field_controller $field * @return field_config_form */ - public function get_field_config_form(field_controller $field): field_config_form { + public function get_field_config_form(field_controller $field) : field_config_form { $form = new field_config_form(null, ['field' => $field]); $form->set_data(api::prepare_field_for_config_form($field)); return $form; @@ -210,7 +210,7 @@ abstract class handler { * @param string $name name of the category, null to generate automatically * @return int id of the new category */ - public function create_category(string $name = null): int { + public function create_category(string $name = null) : int { global $DB; $params = ['component' => $this->get_component(), 'area' => $this->get_area(), 'itemid' => $this->get_itemid()]; @@ -236,7 +236,7 @@ abstract class handler { * @return category_controller * @throws \moodle_exception */ - protected function validate_category(category_controller $category): category_controller { + protected function validate_category(category_controller $category) : category_controller { $categories = $this->get_categories_with_fields(); if (!array_key_exists($category->get('id'), $categories)) { throw new \moodle_exception('categorynotfound', 'core_customfield'); @@ -251,7 +251,7 @@ abstract class handler { * @return field_controller * @throws \moodle_exception */ - protected function validate_field(field_controller $field): field_controller { + protected function validate_field(field_controller $field) : field_controller { if (!array_key_exists($field->get('categoryid'), $this->get_categories_with_fields())) { throw new \moodle_exception('fieldnotfound', 'core_customfield'); } @@ -293,7 +293,7 @@ abstract class handler { * @param category_controller $category * @return bool */ - public function delete_category(category_controller $category): bool { + public function delete_category(category_controller $category) : bool { $category = $this->validate_category($category); $result = api::delete_category($category); $this->clear_configuration_cache(); @@ -317,7 +317,7 @@ abstract class handler { * @param field_controller $field * @return bool */ - public function delete_field_configuration(field_controller $field): bool { + public function delete_field_configuration(field_controller $field) : bool { $field = $this->validate_field($field); $result = api::delete_field_configuration($field); $this->clear_configuration_cache(); @@ -342,7 +342,7 @@ abstract class handler { * * @return bool */ - abstract public function can_configure(): bool; + abstract public function can_configure() : bool; /** * The current user can edit given custom fields on the given instance @@ -355,7 +355,7 @@ abstract class handler { * @param int $instanceid id of the instance or 0 if the instance is being created * @return bool */ - abstract public function can_edit(field_controller $field, int $instanceid = 0): bool; + abstract public function can_edit(field_controller $field, int $instanceid = 0) : bool; /** * The current user can view the value of the custom field for a given custom field and instance @@ -369,7 +369,7 @@ abstract class handler { * @param int $instanceid * @return bool */ - abstract public function can_view(field_controller $field, int $instanceid): bool; + abstract public function can_view(field_controller $field, int $instanceid) : bool; /** * Returns the custom field values for an individual instance @@ -460,7 +460,7 @@ abstract class handler { * @param data_controller[] $fieldsdata * @return string */ - public function display_custom_fields_data(array $fieldsdata): string { + public function display_custom_fields_data(array $fieldsdata) : string { global $PAGE; $output = $PAGE->get_renderer('core_customfield'); $content = ''; @@ -729,7 +729,7 @@ abstract class handler { * * @return field_controller[] */ - public function get_fields(): array { + public function get_fields() : array { $categories = $this->get_categories_with_fields(); $fields = []; foreach ($categories as $category) { @@ -746,7 +746,7 @@ abstract class handler { * @param int $instanceid * @return field_controller[] */ - protected function get_visible_fields(int $instanceid): array { + protected function get_visible_fields(int $instanceid) : array { $handler = $this; return array_filter($this->get_fields(), function($field) use($handler, $instanceid) { @@ -761,7 +761,7 @@ abstract class handler { * @param int $instanceid * @return field_controller[] */ - public function get_editable_fields(int $instanceid): array { + public function get_editable_fields(int $instanceid) : array { $handler = $this; return array_filter($this->get_fields(), function($field) use($handler, $instanceid) { @@ -798,7 +798,7 @@ abstract class handler { * @param field_controller $field * @return string page heading */ - public function setup_edit_page(field_controller $field): string { + public function setup_edit_page(field_controller $field) : string { global $PAGE; // Page context. diff --git a/customfield/classes/output/field_data.php b/customfield/classes/output/field_data.php index 8f515a975de..76f261d21f1 100644 --- a/customfield/classes/output/field_data.php +++ b/customfield/classes/output/field_data.php @@ -63,7 +63,7 @@ class field_data implements \renderable, \templatable { * * @return string */ - public function get_type(): string { + public function get_type() : string { return $this->data->get_field()->get('type'); } @@ -72,7 +72,7 @@ class field_data implements \renderable, \templatable { * * @return string */ - public function get_shortname(): string { + public function get_shortname() : string { return $this->data->get_field()->get('shortname'); } @@ -81,7 +81,7 @@ class field_data implements \renderable, \templatable { * * @return string */ - public function get_name(): string { + public function get_name() : string { return $this->data->get_field()->get_formatted_name(); } @@ -90,7 +90,7 @@ class field_data implements \renderable, \templatable { * * @return data_controller */ - public function get_data_controller(): data_controller { + public function get_data_controller() : data_controller { return $this->data; } diff --git a/customfield/classes/privacy/provider.php b/customfield/classes/privacy/provider.php index 9f3f4088d94..f4077e1f533 100644 --- a/customfield/classes/privacy/provider.php +++ b/customfield/classes/privacy/provider.php @@ -325,7 +325,7 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l * @return array * @throws \coding_exception */ - protected static function get_params(string $component, string $area, array $params): array { + protected static function get_params(string $component, string $area, array $params) : array { if (!empty($params) && (array_keys($params) === range(0, count($params) - 1))) { // Argument $params is not an associative array. throw new \coding_exception('Argument $params must be an associative array!'); diff --git a/customfield/field/checkbox/classes/field_controller.php b/customfield/field/checkbox/classes/field_controller.php index d01df95616d..b25736f0fe5 100644 --- a/customfield/field/checkbox/classes/field_controller.php +++ b/customfield/field/checkbox/classes/field_controller.php @@ -59,7 +59,7 @@ class field_controller extends \core_customfield\field_controller { * @param array $files * @return array associative array of error messages */ - public function config_form_validation(array $data, $files = array()): array { + public function config_form_validation(array $data, $files = array()) : array { $errors = parent::config_form_validation($data, $files); if ($data['configdata']['uniquevalues']) { diff --git a/customfield/field/checkbox/tests/plugin_test.php b/customfield/field/checkbox/tests/plugin_test.php index 6d117500112..4d945332990 100644 --- a/customfield/field/checkbox/tests/plugin_test.php +++ b/customfield/field/checkbox/tests/plugin_test.php @@ -76,7 +76,7 @@ class customfield_checkbox_plugin_testcase extends advanced_testcase { * Get generator * @return core_customfield_generator */ - protected function get_generator(): core_customfield_generator { + protected function get_generator() : core_customfield_generator { return $this->getDataGenerator()->get_plugin_generator('core_customfield'); } diff --git a/customfield/field/date/classes/data_controller.php b/customfield/field/date/classes/data_controller.php index 3419d2562e0..98115e46631 100644 --- a/customfield/field/date/classes/data_controller.php +++ b/customfield/field/date/classes/data_controller.php @@ -90,7 +90,7 @@ class data_controller extends \core_customfield\data_controller { * @param array $files * @return array */ - public function instance_form_validation(array $data, array $files): array { + public function instance_form_validation(array $data, array $files) : array { $errors = parent::instance_form_validation($data, $files); $elementname = $this->get_form_element_name(); diff --git a/customfield/field/date/classes/privacy/provider.php b/customfield/field/date/classes/privacy/provider.php index b9605a5020b..74a6358d2f9 100644 --- a/customfield/field/date/classes/privacy/provider.php +++ b/customfield/field/date/classes/privacy/provider.php @@ -43,7 +43,7 @@ class provider implements \core_privacy\local\metadata\null_provider, customfiel * * @return string */ - public static function get_reason(): string { + public static function get_reason() : string { return 'privacy:metadata'; } diff --git a/customfield/field/date/tests/plugin_test.php b/customfield/field/date/tests/plugin_test.php index 95b4876c7a5..8445c347f15 100644 --- a/customfield/field/date/tests/plugin_test.php +++ b/customfield/field/date/tests/plugin_test.php @@ -73,7 +73,7 @@ class customfield_date_plugin_testcase extends advanced_testcase { * Get generator * @return core_customfield_generator */ - protected function get_generator(): core_customfield_generator { + protected function get_generator() : core_customfield_generator { return $this->getDataGenerator()->get_plugin_generator('core_customfield'); } diff --git a/customfield/field/select/classes/data_controller.php b/customfield/field/select/classes/data_controller.php index 4280429f0cd..682441e6f56 100644 --- a/customfield/field/select/classes/data_controller.php +++ b/customfield/field/select/classes/data_controller.php @@ -96,7 +96,7 @@ class data_controller extends \core_customfield\data_controller { * @param array $files * @return array */ - public function instance_form_validation(array $data, array $files): array { + public function instance_form_validation(array $data, array $files) : array { $errors = parent::instance_form_validation($data, $files); if ($this->get_field()->get_configdata_property('required')) { // Standard required rule does not work on select element. diff --git a/customfield/field/select/classes/field_controller.php b/customfield/field/select/classes/field_controller.php index c0d2dd9ac64..cfce18c7223 100644 --- a/customfield/field/select/classes/field_controller.php +++ b/customfield/field/select/classes/field_controller.php @@ -61,7 +61,7 @@ class field_controller extends \core_customfield\field_controller { * @param \core_customfield\field_controller $field * @return array */ - public static function get_options_array(\core_customfield\field_controller $field): array { + public static function get_options_array(\core_customfield\field_controller $field) : array { if ($field->get_configdata_property('options')) { $options = preg_split("/\s*\n\s*/", trim($field->get_configdata_property('options'))); } else { @@ -78,7 +78,7 @@ class field_controller extends \core_customfield\field_controller { * @param array $files * @return array associative array of error messages */ - public function config_form_validation(array $data, $files = array()): array { + public function config_form_validation(array $data, $files = array()) : array { $options = preg_split("/\s*\n\s*/", trim($data['configdata']['options'])); $errors = []; if (!$options || count($options) < 2) { diff --git a/customfield/field/select/tests/plugin_test.php b/customfield/field/select/tests/plugin_test.php index de630d5e1d4..0ada2bb4885 100644 --- a/customfield/field/select/tests/plugin_test.php +++ b/customfield/field/select/tests/plugin_test.php @@ -77,7 +77,7 @@ class customfield_select_plugin_testcase extends advanced_testcase { * Get generator * @return core_customfield_generator */ - protected function get_generator(): core_customfield_generator { + protected function get_generator() : core_customfield_generator { return $this->getDataGenerator()->get_plugin_generator('core_customfield'); } diff --git a/customfield/field/text/classes/data_controller.php b/customfield/field/text/classes/data_controller.php index a55f57031f5..5d1562b947d 100644 --- a/customfield/field/text/classes/data_controller.php +++ b/customfield/field/text/classes/data_controller.php @@ -72,7 +72,7 @@ class data_controller extends \core_customfield\data_controller { * @param array $files * @return array */ - public function instance_form_validation(array $data, array $files): array { + public function instance_form_validation(array $data, array $files) : array { $errors = parent::instance_form_validation($data, $files); $maxlength = $this->get_field()->get_configdata_property('maxlength'); diff --git a/customfield/field/text/classes/field_controller.php b/customfield/field/text/classes/field_controller.php index 2c03b6c4c18..ffe6ec76104 100644 --- a/customfield/field/text/classes/field_controller.php +++ b/customfield/field/text/classes/field_controller.php @@ -91,7 +91,7 @@ class field_controller extends \core_customfield\field_controller { * @param array $files * @return array associative array of error messages */ - public function config_form_validation(array $data, $files = array()): array { + public function config_form_validation(array $data, $files = array()) : array { global $CFG; $errors = parent::config_form_validation($data, $files); diff --git a/customfield/field/text/tests/plugin_test.php b/customfield/field/text/tests/plugin_test.php index 7a2379fd6e6..8f625641ef2 100644 --- a/customfield/field/text/tests/plugin_test.php +++ b/customfield/field/text/tests/plugin_test.php @@ -82,7 +82,7 @@ class customfield_text_plugin_testcase extends advanced_testcase { * Get generator * @return core_customfield_generator */ - protected function get_generator(): core_customfield_generator { + protected function get_generator() : core_customfield_generator { return $this->getDataGenerator()->get_plugin_generator('core_customfield'); } diff --git a/customfield/field/textarea/classes/data_controller.php b/customfield/field/textarea/classes/data_controller.php index 943dcba5432..57b0d584f84 100644 --- a/customfield/field/textarea/classes/data_controller.php +++ b/customfield/field/textarea/classes/data_controller.php @@ -59,7 +59,7 @@ class data_controller extends \core_customfield\data_controller { * * @return string */ - protected function get_form_element_name(): string { + protected function get_form_element_name() : string { return parent::get_form_element_name() . '_editor'; } diff --git a/customfield/field/textarea/classes/field_controller.php b/customfield/field/textarea/classes/field_controller.php index e53d88bda1b..d27f802ceea 100644 --- a/customfield/field/textarea/classes/field_controller.php +++ b/customfield/field/textarea/classes/field_controller.php @@ -42,7 +42,7 @@ class field_controller extends \core_customfield\field_controller { /** * Before delete bulk actions */ - public function delete(): bool { + public function delete() : bool { global $DB; $fs = get_file_storage(); diff --git a/customfield/field/textarea/tests/plugin_test.php b/customfield/field/textarea/tests/plugin_test.php index 2e8619d7ce2..ee846eff4ee 100644 --- a/customfield/field/textarea/tests/plugin_test.php +++ b/customfield/field/textarea/tests/plugin_test.php @@ -78,7 +78,7 @@ class customfield_textarea_plugin_testcase extends advanced_testcase { * Get generator * @return core_customfield_generator */ - protected function get_generator(): core_customfield_generator { + protected function get_generator() : core_customfield_generator { return $this->getDataGenerator()->get_plugin_generator('core_customfield'); } diff --git a/customfield/templates/list.mustache b/customfield/templates/list.mustache index 109da60584b..3265dc79f21 100644 --- a/customfield/templates/list.mustache +++ b/customfield/templates/list.mustache @@ -39,7 +39,7 @@ "itemid": 0, "usescategories": 1, "categories": [ - { "id": 0, + { "id": "0", "nameeditable": "Other fields", "addfieldmenu": "Add field", "fields": [ @@ -47,7 +47,7 @@ { "id": 0, "name": "Another field", "shortname": "checkme", "type": "Checkbox" } ] }, - { "id": 0, + { "id": "00", "nameeditable": "Empty category", "addfieldmenu": "Add field", "fields": [] } diff --git a/customfield/tests/api_test.php b/customfield/tests/api_test.php index cbe087a8cda..45d50d1712e 100644 --- a/customfield/tests/api_test.php +++ b/customfield/tests/api_test.php @@ -48,7 +48,7 @@ class core_customfield_api_testcase extends advanced_testcase { * Get generator * @return core_customfield_generator */ - protected function get_generator(): core_customfield_generator { + protected function get_generator() : core_customfield_generator { return $this->getDataGenerator()->get_plugin_generator('core_customfield'); } diff --git a/customfield/tests/category_controller_test.php b/customfield/tests/category_controller_test.php index bafe5a87a0d..656bc5bc79d 100644 --- a/customfield/tests/category_controller_test.php +++ b/customfield/tests/category_controller_test.php @@ -47,7 +47,7 @@ class core_customfield_category_controller_testcase extends advanced_testcase { * Get generator * @return core_customfield_generator */ - protected function get_generator(): core_customfield_generator { + protected function get_generator() : core_customfield_generator { return $this->getDataGenerator()->get_plugin_generator('core_customfield'); } diff --git a/customfield/tests/data_controller_test.php b/customfield/tests/data_controller_test.php index 9fd4d86a44f..e29ad463d02 100644 --- a/customfield/tests/data_controller_test.php +++ b/customfield/tests/data_controller_test.php @@ -45,7 +45,7 @@ class core_customfield_data_controller_testcase extends advanced_testcase { * Get generator * @return core_customfield_generator */ - protected function get_generator(): core_customfield_generator { + protected function get_generator() : core_customfield_generator { return $this->getDataGenerator()->get_plugin_generator('core_customfield'); } diff --git a/customfield/tests/field_controller_test.php b/customfield/tests/field_controller_test.php index 2209e9d7366..b7044695be9 100644 --- a/customfield/tests/field_controller_test.php +++ b/customfield/tests/field_controller_test.php @@ -49,7 +49,7 @@ class core_customfield_field_controller_testcase extends advanced_testcase { * Get generator * @return core_customfield_generator */ - protected function get_generator(): core_customfield_generator { + protected function get_generator() : core_customfield_generator { return $this->getDataGenerator()->get_plugin_generator('core_customfield'); } diff --git a/customfield/tests/generator/lib.php b/customfield/tests/generator/lib.php index 1f994623663..06cfe479f97 100644 --- a/customfield/tests/generator/lib.php +++ b/customfield/tests/generator/lib.php @@ -80,7 +80,7 @@ class core_customfield_generator extends component_generator_base { * @param array|stdClass $record * @return field_controller */ - public function create_field($record): field_controller { + public function create_field($record) : field_controller { $this->fieldcount++; $i = $this->fieldcount; $record = (object) $record; @@ -149,7 +149,7 @@ class core_customfield_generator extends component_generator_base { * @param mixed $value * @return \core_customfield\data_controller */ - public function add_instance_data(field_controller $field, int $instanceid, $value): \core_customfield\data_controller { + public function add_instance_data(field_controller $field, int $instanceid, $value) : \core_customfield\data_controller { $data = \core_customfield\data_controller::create(0, (object)['instanceid' => $instanceid], $field); $data->set('contextid', $data->get_context()->id); diff --git a/customfield/tests/generator_test.php b/customfield/tests/generator_test.php index c5335c37d9f..4788d9cf347 100644 --- a/customfield/tests/generator_test.php +++ b/customfield/tests/generator_test.php @@ -39,7 +39,7 @@ class core_customfield_generator_testcase extends advanced_testcase { * Get generator * @return core_customfield_generator */ - protected function get_generator(): core_customfield_generator { + protected function get_generator() : core_customfield_generator { return $this->getDataGenerator()->get_plugin_generator('core_customfield'); } diff --git a/customfield/tests/privacy_test.php b/customfield/tests/privacy_test.php index 8dfdb416d1f..9a15ced5658 100644 --- a/customfield/tests/privacy_test.php +++ b/customfield/tests/privacy_test.php @@ -93,7 +93,7 @@ class core_customfield_privacy_testcase extends provider_testcase { * Get generator * @return core_customfield_generator */ - protected function get_generator(): core_customfield_generator { + protected function get_generator() : core_customfield_generator { return $this->getDataGenerator()->get_plugin_generator('core_customfield'); } diff --git a/lib/adminlib.php b/lib/adminlib.php index 1693dde0533..e5e3b10e467 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -7262,6 +7262,10 @@ class admin_setting_manageformats extends admin_setting { /** * Custom fields manager. Allows to enable/disable custom fields and jump to settings. + * + * @package core + * @copyright 2018 Toni Barbera + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class admin_setting_managecustomfields extends admin_setting { diff --git a/lib/classes/plugininfo/customfield.php b/lib/classes/plugininfo/customfield.php index f830b612544..00ea443270e 100644 --- a/lib/classes/plugininfo/customfield.php +++ b/lib/classes/plugininfo/customfield.php @@ -30,6 +30,10 @@ defined('MOODLE_INTERNAL') || die(); /** * Class for admin tool plugins + * + * @package core + * @copyright 2018 Toni Barbera {@link http://www.moodle.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class customfield extends base { @@ -80,7 +84,6 @@ class customfield extends base { * This is intended for disabling of plugin, some DB table purging, etc. * * NOTE: to be called from uninstall_plugin() only. - * @private */ public function uninstall_cleanup() { global $DB; diff --git a/lib/testing/generator/data_generator.php b/lib/testing/generator/data_generator.php index 1c2b54f7d3b..977e78382c6 100644 --- a/lib/testing/generator/data_generator.php +++ b/lib/testing/generator/data_generator.php @@ -427,7 +427,7 @@ EOD; } if (!empty($record['customfields'])) { - foreach($record['customfields'] as $field) { + foreach ($record['customfields'] as $field) { $record['customfield_'.$field['shortname']] = $field['value']; } } @@ -1185,7 +1185,7 @@ EOD; * @param array $data Array with data['name'] of category * @return \core_customfield\category_controller The created category */ - public function create_custom_field_category($data): \core_customfield\category_controller { + public function create_custom_field_category($data) : \core_customfield\category_controller { return $this->get_plugin_generator('core_customfield')->create_category($data); } @@ -1195,7 +1195,7 @@ EOD; * @param array $data Array with 'name', 'shortname' and 'type' of the field * @return \core_customfield\field_controller The created field */ - public function create_custom_field($data): \core_customfield\field_controller { + public function create_custom_field($data) : \core_customfield\field_controller { global $DB; if (empty($data['categoryid']) && !empty($data['category'])) { $data['categoryid'] = $DB->get_field('customfield_category', 'id', ['name' => $data['category']]);