More tests and error handling
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@ -5,6 +5,8 @@ namespace App\Notification;
|
||||
use Ntfy\Server;
|
||||
use Ntfy\Message;
|
||||
use Ntfy\Client;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class Ntfy implements NotificationInterface
|
||||
{
|
||||
@ -31,18 +33,30 @@ class Ntfy implements NotificationInterface
|
||||
|
||||
public function setTopic(string $topic): void
|
||||
{
|
||||
if (strlen($topic) < 1 || strlen($topic) >= 256) {
|
||||
throw new InvalidArgumentException("Invalid topic length");
|
||||
}
|
||||
|
||||
$this->topic = $topic;
|
||||
}
|
||||
|
||||
public function getTopic(): string
|
||||
{
|
||||
return $this->topic;
|
||||
}
|
||||
|
||||
public function send(string $title, string $message): void
|
||||
{
|
||||
assert(strlen($title) > 0);
|
||||
assert(strlen($title) < 256);
|
||||
assert(strlen($message) > 0);
|
||||
assert(strlen($message) < 4096);
|
||||
if (strlen($title) < 1 || strlen($title) >= 256) {
|
||||
throw new InvalidArgumentException("Invalid title length");
|
||||
}
|
||||
|
||||
if (strlen($message) < 1 || strlen($message) >= 4096) {
|
||||
throw new InvalidArgumentException("Invalid message length");
|
||||
}
|
||||
|
||||
$msg = new Message();
|
||||
$msg->topic($this->topic);
|
||||
$msg->topic($this->getTopic());
|
||||
$msg->title($title);
|
||||
$msg->body($message);
|
||||
$this->client->send($msg);
|
||||
|
Reference in New Issue
Block a user