Skip to content

Commit

Permalink
bug fix in src/Validation.php
Browse files Browse the repository at this point in the history
  • Loading branch information
amirfaramarzi committed Sep 9, 2021
1 parent a6aed7d commit 4969a04
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Tower;

use ArrayAccess;
use Illuminate\Support\Enumerable;
use Tower\Validation\Rules;

class Validation
Expand All @@ -23,24 +21,11 @@ public function __construct(array $data , array $rules)
$this->validate();
}

protected function existsData(Enumerable|ArrayAccess|array $array, string|int $key): bool
protected function existsData(array $array, string|int $key): bool
{
if ($array instanceof Enumerable) {
return $array->has($key);
}

if ($array instanceof ArrayAccess) {
return $array->offsetExists($key);
}

return array_key_exists($key, $array);
}

protected function accessibleData(mixed $value): bool
{
return is_array($value) || $value instanceof ArrayAccess;
}

protected function collapseData(array $array): array
{
$results = [];
Expand Down Expand Up @@ -81,7 +66,7 @@ protected function getData(mixed $target, string|array|int|null $key, mixed $def
return in_array('*', $key) ? $this->collapseData($result) : $result;
}

if ($this->accessibleData($target) && $this->existsData($target, $segment)) {
if (is_array($target) && $this->existsData($target, $segment)) {
$target = $target[$segment];
} else {
return value($default);
Expand Down

0 comments on commit 4969a04

Please sign in to comment.