From b1ac65dca47dd3aede6f8149177180ca9f240e9d Mon Sep 17 00:00:00 2001 From: Owen Nelson Date: Fri, 5 Jul 2024 12:14:30 -0700 Subject: [PATCH] Libs(PHP): extract helper fn is_postitive_integer Motivated by superlinter complaining about how long a line was. --- php/src/Webhook.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/php/src/Webhook.php b/php/src/Webhook.php index 6f051d63c..c1459c139 100644 --- a/php/src/Webhook.php +++ b/php/src/Webhook.php @@ -70,8 +70,7 @@ public function verify($payload, $headers) public function sign($msgId, $timestamp, $payload) { - $is_positive_integer = is_numeric($timestamp) && !is_float($timestamp + 0) && (int) $timestamp == $timestamp && (int) $timestamp > 0; - if (!$is_positive_integer) { + if (!self::isPositiveInteger($timestamp)) { throw new Exception\WebhookSigningException("Invalid timestamp"); } $toSign = "{$msgId}.{$timestamp}.{$payload}"; @@ -97,4 +96,9 @@ private function verifyTimestamp($timestampHeader) } return $timestamp; } + + private function isPositiveInteger($v) + { + return is_numeric($v) && !is_float($v + 0) && (int) $v == $v && (int) $v > 0; + } }