Skip to content

Commit f29210c

Browse files
committed
refactor: use compare equals 1 for preg_match() return on array_filter
1 parent a2ec505 commit f29210c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

system/Helpers/form_helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,10 @@ function validation_show_error(string $field, string $template = 'single'): stri
739739
$config = config(Validation::class);
740740
$view = service('renderer');
741741

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

747747
if ($errors === []) {
748748
return '';

system/Validation/Validation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function run(?array $data = null, ?string $group = null, $dbGroup = null)
176176

177177
$values = array_filter(
178178
$flattenedArray,
179-
static fn ($key): false|int => preg_match(self::getRegex($field), $key),
179+
static fn ($key): bool => preg_match(self::getRegex($field), $key) === 1,
180180
ARRAY_FILTER_USE_KEY
181181
);
182182

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

868868
$errors = array_filter(
869869
$this->getErrors(),
870-
static fn ($key): false|int => preg_match(self::getRegex($field), $key),
870+
static fn ($key): bool => preg_match(self::getRegex($field), $key) === 1,
871871
ARRAY_FILTER_USE_KEY
872872
);
873873

0 commit comments

Comments
 (0)