Skip to content

Commit

Permalink
MDL-57898 core_customfield: coding style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Jan 18, 2019
1 parent c1e15d2 commit bbf60b1
Show file tree
Hide file tree
Showing 45 changed files with 102 additions and 92 deletions.
10 changes: 5 additions & 5 deletions course/classes/customfield/course_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function can_edit(field_controller $field, int $instanceid = 0) : bool {
* @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;
Expand Down Expand Up @@ -146,7 +146,7 @@ protected function get_parent_context() : \context {
*
* @return \context the context for configuration
*/
public function get_configuration_context(): \context {
public function get_configuration_context() : \context {
return \context_system::instance();
}

Expand All @@ -155,7 +155,7 @@ public function get_configuration_context(): \context {
*
* @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');
}

Expand All @@ -165,7 +165,7 @@ public function get_configuration_url(): \moodle_url {
* @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 {
Expand Down Expand Up @@ -230,7 +230,7 @@ public function restore_instance_data_from_backup(\restore_task $task, array $da
* @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');

Expand Down
4 changes: 2 additions & 2 deletions course/classes/list_element.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function get_course_contacts() {
*
* @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);
}
Expand All @@ -217,7 +217,7 @@ public function get_custom_fields(): array {
*
* @return bool
*/
public function has_custom_fields(): bool {
public function has_custom_fields() : bool {
$customfields = $this->get_custom_fields();
return !empty($customfields);
}
Expand Down
9 changes: 6 additions & 3 deletions course/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,8 @@ public static function get_courses_returns() {
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'
Expand Down Expand Up @@ -2548,8 +2549,10 @@ protected static function get_course_structure($onlypublicdata = true) {
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),
Expand Down
2 changes: 1 addition & 1 deletion course/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public function test_create_courses() {
// 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',
Expand Down
12 changes: 6 additions & 6 deletions customfield/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand All @@ -69,7 +69,7 @@ public static function get_instance_fields_data(array $fields, int $instanceid,
* 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.
Expand Down Expand Up @@ -230,7 +230,7 @@ public static function move_field(field_controller $field, int $categoryid, int
*
* @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'));
Expand Down Expand Up @@ -318,7 +318,7 @@ public static function save_category(category_controller $category) {
* @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.
Expand All @@ -339,7 +339,7 @@ public static function delete_category(category_controller $category): bool {
* @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 = [];
Expand Down Expand Up @@ -397,7 +397,7 @@ public static function get_categories_with_fields(string $component, string $are
* @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');
Expand Down
2 changes: 1 addition & 1 deletion customfield/classes/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions customfield/classes/category_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function __construct(int $id = 0, \stdClass $record = null) {
* @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.
Expand Down Expand Up @@ -180,7 +180,7 @@ public function add_field(field_controller $field) {
*
* @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'));
}
Expand Down Expand Up @@ -224,7 +224,7 @@ final public function to_record() {
*
* @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]);
}
Expand Down
2 changes: 1 addition & 1 deletion customfield/classes/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions customfield/classes/data_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(int $id, \stdClass $record) {
* @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.
Expand Down Expand Up @@ -122,7 +122,7 @@ public static function create(int $id, \stdClass $record = null, field_controlle
*
* @return string
*/
protected function get_form_element_name(): string {
protected function get_form_element_name() : string {
return 'customfield_' . $this->get_field()->get('shortname');
}

Expand Down Expand Up @@ -185,7 +185,7 @@ public function save() {
*
* @return field_controller
*/
public function get_field(): field_controller {
public function get_field() : field_controller {
return $this->field;
}

Expand Down Expand Up @@ -223,7 +223,7 @@ public function instance_form_before_set_data(\stdClass $instance) {
* @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 === '';
}
Expand All @@ -236,7 +236,7 @@ protected function is_empty($value): bool {
* @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} = ?";
Expand All @@ -255,7 +255,7 @@ protected function is_unique($value): bool {
* @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) {
Expand All @@ -281,7 +281,7 @@ public function instance_form_definition_after_data(\MoodleQuickForm $mform) {
*
* @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));
Expand Down
2 changes: 1 addition & 1 deletion customfield/classes/event/category_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function init() {
* @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(),
Expand Down
2 changes: 1 addition & 1 deletion customfield/classes/event/category_deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function init() {
* @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(),
Expand Down
2 changes: 1 addition & 1 deletion customfield/classes/event/category_updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function init() {
* @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(),
Expand Down
2 changes: 1 addition & 1 deletion customfield/classes/event/field_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function init() {
* @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(),
Expand Down
2 changes: 1 addition & 1 deletion customfield/classes/event/field_deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function init() {
* @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(),
Expand Down
2 changes: 1 addition & 1 deletion customfield/classes/event/field_updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function init() {
* @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(),
Expand Down
4 changes: 2 additions & 2 deletions customfield/classes/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -91,7 +91,7 @@ protected static function define_properties(): array {
*
* @return array
*/
protected function get_configdata(): array {
protected function get_configdata() : array {
return json_decode($this->raw_get('configdata'), true) ?? array();
}
}
12 changes: 6 additions & 6 deletions customfield/classes/field_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function __construct(int $id = 0, \stdClass $record = null) {
* @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.
Expand Down Expand Up @@ -132,7 +132,7 @@ public static function create(int $id, \stdClass $record = null, category_contro
* @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();
}

Expand Down Expand Up @@ -167,7 +167,7 @@ final public function set($property, $value) {
*
* @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();
Expand Down Expand Up @@ -196,7 +196,7 @@ final public function to_record() {
*
* @return category_controller
*/
public final function get_category(): category_controller {
public final function get_category() : category_controller {
return $this->category;
}

Expand All @@ -219,7 +219,7 @@ public function get_configdata_property(string $property) {
*
* @return handler
*/
public final function get_handler(): handler {
public final function get_handler() : handler {
return $this->get_category()->get_handler();
}

Expand All @@ -245,7 +245,7 @@ public abstract function config_form_definition(\MoodleQuickForm $mform);
*
* @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]);
}
Expand Down
Loading

0 comments on commit bbf60b1

Please sign in to comment.