Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 24 additions & 24 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Validatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@

namespace Attributes\Validation;

use ArrayAccess;
use ArrayObject;
use Attributes\Validation\Exceptions\ValidationException;

interface Validatable
{
/**
* @param array|ArrayAccess $data - Data to be validated
* @param array|ArrayObject $data - Data to be validated
* @param object $model - Model to validate against
*
* @throws ValidationException - If the validation fails
*/
public function validate(array|ArrayAccess $data, object $model): object;
public function validate(array|ArrayObject $data, object $model): object;

/**
* @param array|ArrayAccess $data - Data to be validated
* @param array|ArrayObject $data - Data to be validated
* @param callable $call - Callable to be validated
*
* @returns array - Arguments in a sequence order for the given function
*
* @throws ValidationException - If the validation fails
*/
public function validateCallable(array|ArrayAccess $data, callable $call): array;
public function validateCallable(array|ArrayObject $data, callable $call): array;
}
14 changes: 7 additions & 7 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Attributes\Validation;

use ArrayAccess;
use ArrayObject;
use Attributes\Options;
use Attributes\Options\Exceptions\InvalidOptionException;
use Attributes\Validation\Exceptions\ContextPropertyException;
Expand Down Expand Up @@ -52,7 +52,7 @@ public function __construct(?PropertyValidator $validator = null, bool $stopFirs
/**
* Validates a given data according to a given model
*
* @param array|ArrayAccess $data - Data to validate
* @param array|ArrayObject $data - Data to validate
* @param string|object $model - Model to validate against
* @return object - Model populated with the validated data
*
Expand All @@ -61,7 +61,7 @@ public function __construct(?PropertyValidator $validator = null, bool $stopFirs
* @throws ReflectionException
* @throws InvalidOptionException
*/
public function validate(array|ArrayAccess $data, string|object $model): object
public function validate(array|ArrayObject $data, string|object $model): object
{
$currentLevel = $this->context->getOptional('internal.recursionLevel', 0);
$maxRecursionLevel = $this->context->getOptional('internal.maxRecursionLevel', 30);
Expand All @@ -87,7 +87,7 @@ public function validate(array|ArrayAccess $data, string|object $model): object
$aliasName = $this->getAliasName($reflectionProperty, $defaultAliasGenerator);
$this->context->push('internal.currentProperty', $propertyName);

if (! array_key_exists($aliasName, $data)) {
if (! array_key_exists($aliasName, (array) $data)) {
if (! $reflectionProperty->isInitialized($validModel)) {
try {
$errorInfo->addError("Missing required property '$aliasName'");
Expand Down Expand Up @@ -128,7 +128,7 @@ public function validate(array|ArrayAccess $data, string|object $model): object
/**
* Validates a given data according to a given model
*
* @param array|ArrayAccess $data - Data to validate
* @param array|ArrayObject $data - Data to validate
* @param callable $call - Callable to validate data against
* @return array - Returns an array with the necessary arguments for the callable
*
Expand All @@ -137,7 +137,7 @@ public function validate(array|ArrayAccess $data, string|object $model): object
* @throws ReflectionException
* @throws InvalidOptionException
*/
public function validateCallable(array|ArrayAccess $data, callable $call): array
public function validateCallable(array|ArrayObject $data, callable $call): array
{
$arguments = [];
$reflectionFunction = new ReflectionFunction($call);
Expand All @@ -153,7 +153,7 @@ public function validateCallable(array|ArrayAccess $data, callable $call): array
$aliasName = $this->getAliasName($parameter, $defaultAliasGenerator);
$this->context->push('internal.currentProperty', $propertyName);

if (! array_key_exists($aliasName, $data) && ! array_key_exists($index, $data)) {
if (! array_key_exists($aliasName, (array) $data) && ! array_key_exists($index, (array) $data)) {
if (! $parameter->isDefaultValueAvailable()) {
try {
$errorInfo->addError("Missing required argument '$aliasName'");
Expand Down