From 22b02f8b957bf1b5d4f66049544c4eec7c26c3f2 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Thu, 12 Jan 2023 13:57:10 +0100 Subject: [PATCH] BUGFIX: Handle ArrayAccess in DataStructure validator gracefully while the data structure validator accepted array acces it threw errors when an object actually used this because array_key_exists does not allow passing arrays. --- Classes/Validators/DataStructureValidator.php | 6 +----- Classes/Validators/ShapeValidator.php | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Classes/Validators/DataStructureValidator.php b/Classes/Validators/DataStructureValidator.php index 1a5eec6..de1ad28 100644 --- a/Classes/Validators/DataStructureValidator.php +++ b/Classes/Validators/DataStructureValidator.php @@ -37,11 +37,7 @@ protected function isValid($value) $result = $this->getResult() ?: new Result(); foreach ($this->options['dataStructure'] as $key => $subValidator) { if (is_array($value) || ($value instanceof \ArrayAccess)) { - if (array_key_exists($key, $value)) { - $subValue = $value[$key]; - } else { - $subValue = null; - } + $subValue = $value[$key] ?? null; } elseif (ObjectAccess::isPropertyGettable($value, $key)) { $subValue = ObjectAccess::getPropertyPath($value, $key); } else { diff --git a/Classes/Validators/ShapeValidator.php b/Classes/Validators/ShapeValidator.php index b0de0c5..2a0476f 100644 --- a/Classes/Validators/ShapeValidator.php +++ b/Classes/Validators/ShapeValidator.php @@ -37,11 +37,7 @@ protected function isValid($value) $result = $this->getResult() ?: new Result(); foreach ($this->options['shape'] as $key => $subValidator) { if (is_array($value) || ($value instanceof \ArrayAccess)) { - if (array_key_exists($key, $value)) { - $subValue = $value[$key]; - } else { - $subValue = null; - } + $subValue = $value[$key] ?? null; } elseif (ObjectAccess::isPropertyGettable($value, $key)) { $subValue = ObjectAccess::getPropertyPath($value, $key); } else {