From 3633d6e27fd19e8e8151650280f4913b38eda494 Mon Sep 17 00:00:00 2001 From: Joe Harvey Date: Tue, 24 Jan 2017 15:55:35 +0000 Subject: [PATCH 1/3] Updating all setter methods on DBDate to return an instance of themselves --- src/ORM/FieldType/DBDate.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ORM/FieldType/DBDate.php b/src/ORM/FieldType/DBDate.php index 9ec054988..f336d63e4 100644 --- a/src/ORM/FieldType/DBDate.php +++ b/src/ORM/FieldType/DBDate.php @@ -33,6 +33,7 @@ class DBDate extends DBField * @config * @see DBDateTime::nice_format * @see DBTime::nice_format + * @return $this */ private static $nice_format = 'd/m/Y'; @@ -42,18 +43,19 @@ class DBDate extends DBField // don't try to evaluate empty values with strtotime() below, as it returns "1970-01-01" when it should be // saved as NULL in database $this->value = null; - return; + return $this; } // @todo This needs tidy up (what if you only specify a month and a year, for example?) if (is_array($value)) { if (!empty($value['Day']) && !empty($value['Month']) && !empty($value['Year'])) { $this->value = $value['Year'] . '-' . $value['Month'] . '-' . $value['Day']; - return; - } else { - // return nothing (so checks below don't fail on an empty array) - return null; } + /* + * return $this whether successfully set values from array based + * input or not (so checks below don't fail on an empty array) + */ + return $this; } // Default to NZ date format - strtotime expects a US date @@ -67,12 +69,11 @@ class DBDate extends DBField try { $date = new DateTime($value); $this->value = $date->format('Y-m-d'); - return; } catch (Exception $e) { $this->value = null; - return; } } + return $this; } /** From 38e86f04d8ca7379c5fece498db268bb6755f880 Mon Sep 17 00:00:00 2001 From: Joe Harvey Date: Tue, 24 Jan 2017 15:56:51 +0000 Subject: [PATCH 2/3] Updating all setter methods on DBField to return an instance of themselves --- src/ORM/FieldType/DBField.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ORM/FieldType/DBField.php b/src/ORM/FieldType/DBField.php index 83bfb6a3c..4a777102b 100644 --- a/src/ORM/FieldType/DBField.php +++ b/src/ORM/FieldType/DBField.php @@ -148,7 +148,7 @@ abstract class DBField extends ViewableData * * @param string $name * - * @return DBField + * @return $this */ public function setName($name) { @@ -196,10 +196,12 @@ abstract class DBField extends ViewableData * @param bool $markChanged Indicate wether this field should be marked changed. * Set to FALSE if you are initializing this field after construction, rather * than setting a new value. + * @return $this */ public function setValue($value, $record = null, $markChanged = true) { $this->value = $value; + return $this; } /** @@ -446,7 +448,9 @@ abstract class DBField extends ViewableData { $fieldName = $this->name; if (empty($fieldName)) { - throw new \BadMethodCallException("DBField::saveInto() Called on a nameless '" . get_class($this) . "' object"); + throw new \BadMethodCallException( + "DBField::saveInto() Called on a nameless '" . get_class($this) . "' object" + ); } $dataObject->$fieldName = $this->value; } From daeb3d7abf69ab51788367f90f984cd398a47580 Mon Sep 17 00:00:00 2001 From: Joe Harvey Date: Tue, 24 Jan 2017 15:57:02 +0000 Subject: [PATCH 3/3] Updating all setter methods on DBMoney to return an instance of themselves --- src/ORM/FieldType/DBMoney.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ORM/FieldType/DBMoney.php b/src/ORM/FieldType/DBMoney.php index 95923e4bf..4e8e6679d 100644 --- a/src/ORM/FieldType/DBMoney.php +++ b/src/ORM/FieldType/DBMoney.php @@ -103,10 +103,12 @@ class DBMoney extends DBComposite /** * @param string $currency * @param bool $markChanged + * @return $this */ public function setCurrency($currency, $markChanged = true) { $this->setField('Currency', $currency, $markChanged); + return $this; } /** @@ -120,10 +122,12 @@ class DBMoney extends DBComposite /** * @param float $amount * @param bool $markChanged + * @return $this */ public function setAmount($amount, $markChanged = true) { $this->setField('Amount', (float)$amount, $markChanged); + return $this; } /** @@ -145,11 +149,13 @@ class DBMoney extends DBComposite /** * @param string $locale + * @return $this */ public function setLocale($locale) { $this->locale = $locale; $this->currencyLib->setLocale($locale); + return $this; } /** @@ -214,10 +220,12 @@ class DBMoney extends DBComposite /** * @param array $arr + * @return $this */ public function setAllowedCurrencies($arr) { $this->allowedCurrencies = $arr; + return $this; } /**