Skip to content

Commit

Permalink
refactor: use compare equals 1 for preg_match() return on array_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Dec 28, 2024
1 parent a2ec505 commit f29210c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions system/Helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,10 @@ function validation_show_error(string $field, string $template = 'single'): stri
$config = config(Validation::class);
$view = service('renderer');

$errors = array_filter(validation_errors(), static fn ($key): false|int => preg_match(
$errors = array_filter(validation_errors(), static fn ($key): bool => preg_match(
'/^' . str_replace(['\.\*', '\*\.'], ['\..+', '.+\.'], preg_quote($field, '/')) . '$/',
$key
), ARRAY_FILTER_USE_KEY);
) === 1, ARRAY_FILTER_USE_KEY);

if ($errors === []) {
return '';
Expand Down
4 changes: 2 additions & 2 deletions system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function run(?array $data = null, ?string $group = null, $dbGroup = null)

$values = array_filter(
$flattenedArray,
static fn ($key): false|int => preg_match(self::getRegex($field), $key),
static fn ($key): bool => preg_match(self::getRegex($field), $key) === 1,
ARRAY_FILTER_USE_KEY
);

Expand Down Expand Up @@ -867,7 +867,7 @@ public function getError(?string $field = null): string

$errors = array_filter(
$this->getErrors(),
static fn ($key): false|int => preg_match(self::getRegex($field), $key),
static fn ($key): bool => preg_match(self::getRegex($field), $key) === 1,
ARRAY_FILTER_USE_KEY
);

Expand Down

0 comments on commit f29210c

Please sign in to comment.