From d66298e9c62dcf697dcee12decc336fb84852f87 Mon Sep 17 00:00:00 2001 From: "Abdulmhsen B. A. A." Date: Mon, 17 Jun 2024 13:26:12 +0300 Subject: [PATCH] renamed suppression message to rule. --- src/API/System/Suppressor.php | 16 ++++++++-------- src/Libs/LogSuppressor.php | 8 ++++---- tests/Libs/LogSuppressorTest.php | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/API/System/Suppressor.php b/src/API/System/Suppressor.php index 420a4aed..fc5c12ef 100644 --- a/src/API/System/Suppressor.php +++ b/src/API/System/Suppressor.php @@ -48,29 +48,29 @@ final class Suppressor { $params = DataUtil::fromRequest($request); - if (null === ($message = $params->get('message')) || empty($message)) { - return api_error('Message text is required.', HTTP_STATUS::HTTP_BAD_REQUEST); + if (null === ($rule = $params->get('rule')) || empty($rule)) { + return api_error('Rule is required.', HTTP_STATUS::HTTP_BAD_REQUEST); } if (null === ($type = $params->get('type')) || empty($type)) { - return api_error('Message type is required.', HTTP_STATUS::HTTP_BAD_REQUEST); + return api_error('Rule type is required.', HTTP_STATUS::HTTP_BAD_REQUEST); } $type = strtolower($type); if (null === ($example = $params->get('example')) || empty($example)) { - return api_error('Message example is required.', HTTP_STATUS::HTTP_BAD_REQUEST); + return api_error('Rule example is required.', HTTP_STATUS::HTTP_BAD_REQUEST); } if ('regex' === $type) { - if (false === @preg_match($message, '')) { + if (false === @preg_match($rule, '')) { return api_error('Invalid regex pattern.', HTTP_STATUS::HTTP_BAD_REQUEST); } - if (false === @preg_match($message, $example)) { + if (false === @preg_match($rule, $example)) { return api_error('Example does not match the regex pattern.', HTTP_STATUS::HTTP_BAD_REQUEST); } } else { - if (false === str_contains($example, $message)) { + if (false === str_contains($example, $rule)) { return api_error('Example does not contain the message text.', HTTP_STATUS::HTTP_BAD_REQUEST); } } @@ -81,7 +81,7 @@ final class Suppressor $data = [ 'type' => $type, - 'message' => $message, + 'rule' => $rule, 'example' => $example, ]; diff --git a/src/Libs/LogSuppressor.php b/src/Libs/LogSuppressor.php index c71cf15f..61b55037 100644 --- a/src/Libs/LogSuppressor.php +++ b/src/Libs/LogSuppressor.php @@ -58,18 +58,18 @@ final class LogSuppressor implements iHandler } foreach (self::$suppress as $suppress) { - $message = ag($suppress, 'message', ''); - if (empty($message)) { + $rule = ag($suppress, 'rule', ''); + if (empty($rule)) { continue; } if ('regex' === ag($suppress, 'type', 'contains')) { - if (1 === @preg_match($message, $log)) { + if (1 === @preg_match($rule, $log)) { return true; } continue; } - if (str_contains($log, $message)) { + if (str_contains($log, $rule)) { return true; } } diff --git a/tests/Libs/LogSuppressorTest.php b/tests/Libs/LogSuppressorTest.php index 636bf60e..813294ec 100644 --- a/tests/Libs/LogSuppressorTest.php +++ b/tests/Libs/LogSuppressorTest.php @@ -17,15 +17,15 @@ class LogSuppressorTest extends TestCase private array $testData = [ 'A7434c91d3440' => [ - 'message' => 'Random string', + 'rule' => 'Random string', 'type' => 'contains', ], 'A7434c91d3441' => [ - 'message' => '/some random \'(\d+)\'/', + 'rule' => '/some random \'(\d+)\'/', 'type' => 'regex', ], 'A7434c91d3442' => [ - 'message' => '', + 'rule' => '', 'type' => 'contains', ], ];