From 645d818eef74997e12675949255a105977055a38 Mon Sep 17 00:00:00 2001 From: artur Date: Mon, 23 Nov 2015 07:18:22 +0200 Subject: [PATCH] Returns object from methods for chaining purpose --- framework/base/Model.php | 3 +++ framework/db/ActiveRecordInterface.php | 1 + framework/db/BaseActiveRecord.php | 9 +++++++++ 3 files changed, 13 insertions(+) diff --git a/framework/base/Model.php b/framework/base/Model.php index 15ab32decb5..4916d73c3e4 100644 --- a/framework/base/Model.php +++ b/framework/base/Model.php @@ -686,6 +686,7 @@ public function getAttributes($names = null, $except = []) * @param array $values attribute values (name => value) to be assigned to the model. * @param boolean $safeOnly whether the assignments should only be done to the safe attributes. * A safe attribute is one that is associated with a validation rule in the current [[scenario]]. + * @return $this * @see safeAttributes() * @see attributes() */ @@ -701,6 +702,8 @@ public function setAttributes($values, $safeOnly = true) } } } + + return $this; } /** diff --git a/framework/db/ActiveRecordInterface.php b/framework/db/ActiveRecordInterface.php index 6c0eba2f880..56b8245759b 100644 --- a/framework/db/ActiveRecordInterface.php +++ b/framework/db/ActiveRecordInterface.php @@ -47,6 +47,7 @@ public function getAttribute($name); * Sets the named attribute value. * @param string $name the attribute name. * @param mixed $value the attribute value. + * @return $this * @see hasAttribute() */ public function setAttribute($name, $value); diff --git a/framework/db/BaseActiveRecord.php b/framework/db/BaseActiveRecord.php index 318361bb5fe..002ab87a8fd 100644 --- a/framework/db/BaseActiveRecord.php +++ b/framework/db/BaseActiveRecord.php @@ -459,6 +459,7 @@ protected function setAttributeInternal($name, $value, $check = true) * @param string $name the attribute name * @param mixed $value the attribute value. * @param boolean $throw Set to false to not throw an exception (used internally). + * @return $this * @see hasAttribute() */ public function setAttribute($name, $value) @@ -466,6 +467,8 @@ public function setAttribute($name, $value) if (!$this->setAttributeInternal($name, $value)) { throw new InvalidParamException(get_class($this) . ' has no attribute named "' . $name . '".'); } + + return $this; } @@ -483,10 +486,13 @@ public function getOldAttributes() * All existing old attribute values will be discarded. * @param array|null $values old attribute values to be set. * If set to `null` this record is considered to be [[isNewRecord|new]]. + * @return $this */ public function setOldAttributes($values) { $this->_oldAttributes = $values; + + return $this; } /** @@ -507,6 +513,7 @@ public function getOldAttribute($name) * Sets the old value of the named attribute. * @param string $name the attribute name * @param mixed $value the old attribute value. + * @return $this * @throws InvalidParamException if the named attribute does not exist. * @see hasAttribute() */ @@ -517,6 +524,8 @@ public function setOldAttribute($name, $value) } else { throw new InvalidParamException(get_class($this) . ' has no attribute named "' . $name . '".'); } + + return $this; } /**