From e5f5f238ed9d5c1c87a6af7eb5f5df602aa5589f Mon Sep 17 00:00:00 2001 From: omer Date: Tue, 27 Feb 2018 13:12:26 +0300 Subject: [PATCH] ADD given field to see expected value and given value in error context --- .../Serialize/Validation/ObjectValidation.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Fabs/Serialize/Validation/ObjectValidation.php b/src/Fabs/Serialize/Validation/ObjectValidation.php index 06ebd2a..0ce5a09 100644 --- a/src/Fabs/Serialize/Validation/ObjectValidation.php +++ b/src/Fabs/Serialize/Validation/ObjectValidation.php @@ -13,6 +13,8 @@ class ObjectValidation extends ValidationBase { /** @var string */ protected $type = null; + /** @var string */ + protected $given = null; /** * @param $type string @@ -26,6 +28,16 @@ public function setType($type) public function isValid($value) { + if ($value === null) { + $this->given = null; + } else { + if (is_object($value)) { + $this->given = get_class($value); + } else { + $this->given = gettype($value); + } + } + if ($value === null) { if ($this->is_required) { return false; @@ -39,6 +51,7 @@ public function isValid($value) public function getValidationName() { - return $this->type; + return 'expected: ' . $this->type . ' given: ' . $this->given; } } +