From 1f29c13ea8bbf883263315453625800939185d0b Mon Sep 17 00:00:00 2001 From: Michael Jervis Date: Fri, 4 Feb 2022 08:58:47 +0000 Subject: [PATCH 1/5] fix: support JsonSerializable on the Validation class --- lib/Braintree/Error/Validation.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Braintree/Error/Validation.php b/lib/Braintree/Error/Validation.php index fc91ccc4..b2b0d941 100644 --- a/lib/Braintree/Error/Validation.php +++ b/lib/Braintree/Error/Validation.php @@ -3,6 +3,7 @@ namespace Braintree\Error; use Braintree\Util; +use JsonSerializable; /** * error object returned as part of a validation error collection @@ -13,7 +14,7 @@ * // phpcs:ignore Generic.Files.LineLength * See our {@link https://developer.paypal.com/braintree/docs/reference/general/result-objects#error-results developer docs} for more information */ -class Validation +class Validation implements JsonSerializable { private $_attribute; private $_code; @@ -40,4 +41,18 @@ public function __get($name) $varName = "_$name"; return isset($this->$varName) ? $this->$varName : null; } + + /** + * Implementation of JsonSerializable + * + * @return array + */ + public function jsonSerialize() + { + return array( + 'code' => $this->__get('code'), + 'attribute' => $this->__get('attribute'), + 'message' => $this->__get('message') + ); + } } From 20aa3123645f9c38163c9d5a3a8cad7e48e68d50 Mon Sep 17 00:00:00 2001 From: Michael Jervis Date: Fri, 4 Feb 2022 09:11:53 +0000 Subject: [PATCH 2/5] fix: add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 054eea86..b63b2370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## 6.5.2 +* Make Error\Validation jsonSerializable ## 6.5.1 * Address PHP 8.1 Deprecation warnings From c49d7477c90d3ce9009da82e52c066c0d64401b0 Mon Sep 17 00:00:00 2001 From: mjervis Date: Mon, 7 Feb 2022 09:56:47 +0000 Subject: [PATCH 3/5] Update CHANGELOG.md Co-authored-by: Blade Barringer --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b63b2370..7a5622f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ -## 6.5.2 +## unreleased * Make Error\Validation jsonSerializable + ## 6.5.1 * Address PHP 8.1 Deprecation warnings From 95462fbdaa0dfe77b47b7ba83ab0a02dd1dd137c Mon Sep 17 00:00:00 2001 From: mjervis Date: Mon, 7 Feb 2022 09:57:00 +0000 Subject: [PATCH 4/5] Update lib/Braintree/Error/Validation.php Co-authored-by: Blade Barringer --- lib/Braintree/Error/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Braintree/Error/Validation.php b/lib/Braintree/Error/Validation.php index b2b0d941..aa409dad 100644 --- a/lib/Braintree/Error/Validation.php +++ b/lib/Braintree/Error/Validation.php @@ -42,7 +42,7 @@ public function __get($name) return isset($this->$varName) ? $this->$varName : null; } - /** + /** * Implementation of JsonSerializable * * @return array From c30785395f62a297294c3ffb023d22c39f61281d Mon Sep 17 00:00:00 2001 From: Michael Jervis Date: Mon, 7 Feb 2022 10:05:19 +0000 Subject: [PATCH 5/5] fix: return type will change to be consistent with other serialize methods --- lib/Braintree/Error/Validation.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Braintree/Error/Validation.php b/lib/Braintree/Error/Validation.php index aa409dad..69bbf3d6 100644 --- a/lib/Braintree/Error/Validation.php +++ b/lib/Braintree/Error/Validation.php @@ -47,6 +47,7 @@ public function __get($name) * * @return array */ + #[\ReturnTypeWillChange] public function jsonSerialize() { return array(