From f29210c0f0ef4c4096d4ac937f1e422ef769673f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 29 Dec 2024 01:13:34 +0700 Subject: [PATCH] refactor: use compare equals 1 for preg_match() return on array_filter --- system/Helpers/form_helper.php | 4 ++-- system/Validation/Validation.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index 6e77a1f36b0c..679008c9731a 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -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 ''; diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index 93524663947e..5b51b403fef9 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -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 ); @@ -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 );