Skip to content

Commit ebe1167

Browse files
committed
chore: Replaced ArrayAccess type-hint by ArrayObject
1 parent faf126b commit ebe1167

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

composer.lock

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Validatable.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@
88

99
namespace Attributes\Validation;
1010

11-
use ArrayAccess;
11+
use ArrayObject;
1212
use Attributes\Validation\Exceptions\ValidationException;
1313

1414
interface Validatable
1515
{
1616
/**
17-
* @param array|ArrayAccess $data - Data to be validated
17+
* @param array|ArrayObject $data - Data to be validated
1818
* @param object $model - Model to validate against
1919
*
2020
* @throws ValidationException - If the validation fails
2121
*/
22-
public function validate(array|ArrayAccess $data, object $model): object;
22+
public function validate(array|ArrayObject $data, object $model): object;
2323

2424
/**
25-
* @param array|ArrayAccess $data - Data to be validated
25+
* @param array|ArrayObject $data - Data to be validated
2626
* @param callable $call - Callable to be validated
2727
*
2828
* @returns array - Arguments in a sequence order for the given function
2929
*
3030
* @throws ValidationException - If the validation fails
3131
*/
32-
public function validateCallable(array|ArrayAccess $data, callable $call): array;
32+
public function validateCallable(array|ArrayObject $data, callable $call): array;
3333
}

src/Validator.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Attributes\Validation;
66

7-
use ArrayAccess;
7+
use ArrayObject;
88
use Attributes\Options;
99
use Attributes\Options\Exceptions\InvalidOptionException;
1010
use Attributes\Validation\Exceptions\ContextPropertyException;
@@ -52,7 +52,7 @@ public function __construct(?PropertyValidator $validator = null, bool $stopFirs
5252
/**
5353
* Validates a given data according to a given model
5454
*
55-
* @param array|ArrayAccess $data - Data to validate
55+
* @param array|ArrayObject $data - Data to validate
5656
* @param string|object $model - Model to validate against
5757
* @return object - Model populated with the validated data
5858
*
@@ -61,7 +61,7 @@ public function __construct(?PropertyValidator $validator = null, bool $stopFirs
6161
* @throws ReflectionException
6262
* @throws InvalidOptionException
6363
*/
64-
public function validate(array|ArrayAccess $data, string|object $model): object
64+
public function validate(array|ArrayObject $data, string|object $model): object
6565
{
6666
$currentLevel = $this->context->getOptional('internal.recursionLevel', 0);
6767
$maxRecursionLevel = $this->context->getOptional('internal.maxRecursionLevel', 30);
@@ -87,7 +87,7 @@ public function validate(array|ArrayAccess $data, string|object $model): object
8787
$aliasName = $this->getAliasName($reflectionProperty, $defaultAliasGenerator);
8888
$this->context->push('internal.currentProperty', $propertyName);
8989

90-
if (! array_key_exists($aliasName, $data)) {
90+
if (! array_key_exists($aliasName, (array) $data)) {
9191
if (! $reflectionProperty->isInitialized($validModel)) {
9292
try {
9393
$errorInfo->addError("Missing required property '$aliasName'");
@@ -128,7 +128,7 @@ public function validate(array|ArrayAccess $data, string|object $model): object
128128
/**
129129
* Validates a given data according to a given model
130130
*
131-
* @param array|ArrayAccess $data - Data to validate
131+
* @param array|ArrayObject $data - Data to validate
132132
* @param callable $call - Callable to validate data against
133133
* @return array - Returns an array with the necessary arguments for the callable
134134
*
@@ -137,7 +137,7 @@ public function validate(array|ArrayAccess $data, string|object $model): object
137137
* @throws ReflectionException
138138
* @throws InvalidOptionException
139139
*/
140-
public function validateCallable(array|ArrayAccess $data, callable $call): array
140+
public function validateCallable(array|ArrayObject $data, callable $call): array
141141
{
142142
$arguments = [];
143143
$reflectionFunction = new ReflectionFunction($call);
@@ -153,7 +153,7 @@ public function validateCallable(array|ArrayAccess $data, callable $call): array
153153
$aliasName = $this->getAliasName($parameter, $defaultAliasGenerator);
154154
$this->context->push('internal.currentProperty', $propertyName);
155155

156-
if (! array_key_exists($aliasName, $data) && ! array_key_exists($index, $data)) {
156+
if (! array_key_exists($aliasName, (array) $data) && ! array_key_exists($index, (array) $data)) {
157157
if (! $parameter->isDefaultValueAvailable()) {
158158
try {
159159
$errorInfo->addError("Missing required argument '$aliasName'");

0 commit comments

Comments
 (0)