Skip to content

Commit

Permalink
Libs(PHP): extract helper fn is_postitive_integer
Browse files Browse the repository at this point in the history
Motivated by superlinter complaining about how long a line was.
  • Loading branch information
svix-onelson committed Jul 5, 2024
1 parent cc3eec6 commit b1ac65d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions php/src/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand All @@ -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;
}
}

0 comments on commit b1ac65d

Please sign in to comment.