Skip to content

Commit

Permalink
MDL-57273 persistent: Improved style
Browse files Browse the repository at this point in the history
Use \blah::class instead of '\\blah' in define_class functions.
Allow chaining of setters by returning $this.
  • Loading branch information
Damyon Wiese committed Jan 23, 2017
1 parent 599acbe commit d581862
Show file tree
Hide file tree
Showing 18 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
class user_evidence_summary_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\user_evidence';
return \core_competency\user_evidence::class;
}

protected static function define_other_properties() {
Expand Down
2 changes: 1 addition & 1 deletion competency/classes/external/competency_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class competency_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\competency';
return \core_competency\competency::class;
}

protected static function define_related() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class competency_framework_exporter extends \core\external\persistent_exporter {
* @return string
*/
protected static function define_class() {
return 'core_competency\\competency_framework';
return \core_competency\competency_framework::class;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion competency/classes/external/course_competency_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
class course_competency_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\course_competency';
return \core_competency\course_competency::class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class course_competency_settings_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\course_competency_settings';
return \core_competency\course_competency_settings::class;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
class course_module_competency_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\course_module_competency';
return \core_competency\course_module_competency::class;
}
}
2 changes: 1 addition & 1 deletion competency/classes/external/evidence_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected static function define_related() {
}

protected static function define_class() {
return 'core_competency\\evidence';
return evidence::class;
}

protected function get_other_values(renderer_base $output) {
Expand Down
2 changes: 1 addition & 1 deletion competency/classes/external/plan_competency_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
class plan_competency_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\plan_competency';
return \core_competency\plan_competency::class;
}
}
2 changes: 1 addition & 1 deletion competency/classes/external/plan_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
class plan_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\plan';
return \core_competency\plan::class;
}

protected static function define_related() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
class related_competency_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\related_competency';
return \core_competency\related_competency::class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
class template_competency_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\template_competency';
return \core_competency\template_competency::class;
}
}
2 changes: 1 addition & 1 deletion competency/classes/external/template_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
class template_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\template';
return \core_competency\template::class;
}

protected function get_other_values(renderer_base $output) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
class user_competency_course_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\user_competency_course';
return \core_competency\user_competency_course::class;
}

protected static function define_related() {
Expand Down
2 changes: 1 addition & 1 deletion competency/classes/external/user_competency_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
class user_competency_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\user_competency';
return user_competency::class;
}

protected static function define_related() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
class user_competency_plan_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\user_competency_plan';
return \core_competency\user_competency_plan::class;
}

protected static function define_related() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class user_evidence_competency_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\user_evidence_competency';
return \core_competency\user_evidence_competency::class;
}

}
2 changes: 1 addition & 1 deletion competency/classes/external/user_evidence_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
class user_evidence_exporter extends \core\external\persistent_exporter {

protected static function define_class() {
return 'core_competency\\user_evidence';
return \core_competency\user_evidence::class;
}

protected static function define_other_properties() {
Expand Down
9 changes: 6 additions & 3 deletions lib/classes/persistent.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ final protected function verify_protected_methods() {
* raw records from the DB.
*
* @param string $property The property name.
* @return mixed
* @return $this
*/
final public function set($property, $value) {
$methodname = 'set_' . $property;
if (method_exists($this, $methodname)) {
return $this->$methodname($value);
$this->$methodname($value);
return $this;
}
return $this->raw_set($property, $value);
}
Expand Down Expand Up @@ -177,7 +178,7 @@ final protected function raw_get($property) {
*
* @param string $property The property name.
* @param mixed $value The value.
* @return mixed
* @return $this
*/
final protected function raw_set($property, $value) {
if (!static::has_property($property)) {
Expand All @@ -188,6 +189,8 @@ final protected function raw_set($property, $value) {
$this->validated = false;
}
$this->data[$property] = $value;

return $this;
}

/**
Expand Down

0 comments on commit d581862

Please sign in to comment.