Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/serializable validation errors #312

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 6.5.2
* Make Error\Validation jsonSerializable
mjervis marked this conversation as resolved.
Show resolved Hide resolved
## 6.5.1
* Address PHP 8.1 Deprecation warnings

Expand Down
17 changes: 16 additions & 1 deletion lib/Braintree/Error/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Braintree\Error;

use Braintree\Util;
use JsonSerializable;

/**
* error object returned as part of a validation error collection
Expand All @@ -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;
Expand All @@ -40,4 +41,18 @@ public function __get($name)
$varName = "_$name";
return isset($this->$varName) ? $this->$varName : null;
}

/**
* Implementation of JsonSerializable
mjervis marked this conversation as resolved.
Show resolved Hide resolved
*
* @return array
*/
public function jsonSerialize()
{
return array(
'code' => $this->__get('code'),
'attribute' => $this->__get('attribute'),
'message' => $this->__get('message')
);
Comment on lines +53 to +57

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return array(
'code' => $this->__get('code'),
'attribute' => $this->__get('attribute'),
'message' => $this->__get('message')
);
return [
'code' => $this->__get('code'),
'attribute' => $this->__get('attribute'),
'message' => $this->__get('message'),
];

}
}