Killing a few "mutants"
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
2023-11-03 12:02:44 +00:00
parent 61001edaa0
commit 66ccb3d8d6
5 changed files with 37 additions and 12 deletions

View File

@ -14,6 +14,8 @@ use InvalidArgumentException;
*/
class Ntfy implements NotificationInterface
{
const TOPIC_MAX_LENGTH = 256;
const MESSAGE_MAX_LENGTH = 4096;
private string $topic = 'default';
/**
@ -42,11 +44,11 @@ class Ntfy implements NotificationInterface
/**
* Set the topic of the notification message.
*
* @param string $topic Topic length between 1 and 256 characters.
* @param string $topic Topic length between 1 and TOPIC_MAX_LENGTH characters.
*/
public function setTopic(string $topic): void
{
if (strlen($topic) < 1 || strlen($topic) >= 256) {
if (!strlen($topic) || strlen($topic) > self::TOPIC_MAX_LENGTH) {
throw new InvalidArgumentException("Invalid topic length");
}
@ -66,11 +68,11 @@ class Ntfy implements NotificationInterface
*/
public function send(string $title, string $message): void
{
if (strlen($title) < 1 || strlen($title) >= 256) {
if (!strlen($title) || strlen($title) > self::TOPIC_MAX_LENGTH) {
throw new InvalidArgumentException("Invalid title length");
}
if (strlen($message) < 1 || strlen($message) >= 4096) {
if (!strlen($message) || strlen($message) > self::MESSAGE_MAX_LENGTH) {
throw new InvalidArgumentException("Invalid message length");
}

View File

@ -38,7 +38,7 @@ class TwigExtension extends AbstractExtension
public function formatBytes($bytes, $precision = 2)
{
$size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB'];
$fact = (int)(floor((strlen((string)$bytes) - 1) / 3));
$fact = (int)floor((strlen((string)$bytes) - 1) / 3);
return sprintf("%.{$precision}f", $bytes / pow(1024, $fact)) . $size[$fact];
}
}