From 638a0d3127c4d4f1182502b88aab54f7d27a2a73 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 27 Dec 2024 10:06:01 +0700 Subject: [PATCH] refactor: various compare !== 1 on preg_match() --- system/Cache/Handlers/FileHandler.php | 2 +- system/Database/BaseBuilder.php | 4 ++-- system/Database/MigrationRunner.php | 2 +- system/Helpers/filesystem_helper.php | 2 +- system/Validation/Rules.php | 4 ++-- system/Validation/StrictRules/Rules.php | 4 ++-- utils/src/Rector/UnderscoreToCamelCaseVariableNameRector.php | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/system/Cache/Handlers/FileHandler.php b/system/Cache/Handlers/FileHandler.php index ea7c00e382e2..525616a71068 100644 --- a/system/Cache/Handlers/FileHandler.php +++ b/system/Cache/Handlers/FileHandler.php @@ -308,7 +308,7 @@ protected function deleteFiles(string $path, bool $delDir = false, bool $htdocs if ($filename !== '.' && $filename !== '..') { if (is_dir($path . DIRECTORY_SEPARATOR . $filename) && $filename[0] !== '.') { $this->deleteFiles($path . DIRECTORY_SEPARATOR . $filename, $delDir, $htdocs, $_level + 1); - } elseif (! $htdocs || in_array(preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename), [0, false], true)) { + } elseif (! $htdocs || preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename) !== 1) { @unlink($path . DIRECTORY_SEPARATOR . $filename); } } diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index 2b947ce952e2..e738a331d608 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -3167,11 +3167,11 @@ protected function compileWhereHaving(string $qbKey): string $op = $this->getOperator($condition); if ( $op === false - || in_array(preg_match( + || preg_match( '/^(\(?)(.*)(' . preg_quote($op, '/') . ')\s*(.*(?regex, $filename), [0, false], true)) { + if (preg_match($this->regex, $filename) !== 1) { return false; } diff --git a/system/Helpers/filesystem_helper.php b/system/Helpers/filesystem_helper.php index fded9f64ef20..d5f2d974e4ad 100644 --- a/system/Helpers/filesystem_helper.php +++ b/system/Helpers/filesystem_helper.php @@ -166,7 +166,7 @@ function delete_files(string $path, bool $delDir = false, bool $htdocs = false, continue; } - if (! $htdocs || in_array(preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename), [0, false], true)) { + if (! $htdocs || preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename) !== 1) { $isDir = $object->isDir(); if ($isDir && $delDir) { rmdir($object->getPathname()); diff --git a/system/Validation/Rules.php b/system/Validation/Rules.php index 7ee680d90698..7f2f0bd941ec 100644 --- a/system/Validation/Rules.php +++ b/system/Validation/Rules.php @@ -140,7 +140,7 @@ public function is_not_unique($str, string $field, array $data): bool if ( $whereField !== null && $whereField !== '' && $whereValue !== null && $whereValue !== '' - && in_array(preg_match('/^\{(\w+)\}$/', $whereValue), [0, false], true) + && preg_match('/^\{(\w+)\}$/', $whereValue) !== 1 ) { $row = $row->where($whereField, $whereValue); } @@ -198,7 +198,7 @@ public function is_unique($str, string $field, array $data): bool if ( $ignoreField !== null && $ignoreField !== '' && $ignoreValue !== null && $ignoreValue !== '' - && in_array(preg_match('/^\{(\w+)\}$/', $ignoreValue), [0, false], true) + && preg_match('/^\{(\w+)\}$/', $ignoreValue) !== 1 ) { $row = $row->where("{$ignoreField} !=", $ignoreValue); } diff --git a/system/Validation/StrictRules/Rules.php b/system/Validation/StrictRules/Rules.php index 3bc130bd93e4..c9b98c479875 100644 --- a/system/Validation/StrictRules/Rules.php +++ b/system/Validation/StrictRules/Rules.php @@ -164,7 +164,7 @@ public function is_not_unique($str, string $field, array $data): bool if ( $whereField !== null && $whereField !== '' && $whereValue !== null && $whereValue !== '' - && in_array(preg_match('/^\{(\w+)\}$/', $whereValue), [0, false], true) + && preg_match('/^\{(\w+)\}$/', $whereValue) !== 1 ) { $row = $row->where($whereField, $whereValue); } @@ -224,7 +224,7 @@ public function is_unique($str, string $field, array $data): bool if ( $ignoreField !== null && $ignoreField !== '' && $ignoreValue !== null && $ignoreValue !== '' - && in_array(preg_match('/^\{(\w+)\}$/', $ignoreValue), [0, false], true) + && preg_match('/^\{(\w+)\}$/', $ignoreValue) !== 1 ) { $row = $row->where("{$ignoreField} !=", $ignoreValue); } diff --git a/utils/src/Rector/UnderscoreToCamelCaseVariableNameRector.php b/utils/src/Rector/UnderscoreToCamelCaseVariableNameRector.php index 381a7dfb3a1c..93817c45bbd5 100644 --- a/utils/src/Rector/UnderscoreToCamelCaseVariableNameRector.php +++ b/utils/src/Rector/UnderscoreToCamelCaseVariableNameRector.php @@ -178,7 +178,7 @@ private function updateDocblock(string $variableName, string $camelCaseName, ?Fu return; } - if (in_array(preg_match(sprintf(self::PARAM_NAME_REGEX, $variableName), $docCommentText), [0, false], true)) { + if (preg_match(sprintf(self::PARAM_NAME_REGEX, $variableName), $docCommentText) !== 1) { return; }