Skip to content

Commit 9caf0a8

Browse files
committed
[Notifier] Add Notification::exception()
1 parent 802eca0 commit 9caf0a8

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

Notification/Notification.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,7 @@ public function __construct(string $subject = '', array $channels = [])
5858
*/
5959
public static function fromThrowable(\Throwable $exception, array $channels = []): self
6060
{
61-
$parts = explode('\\', \get_class($exception));
62-
63-
$notification = new self(sprintf('%s: %s', array_pop($parts), $exception->getMessage()), $channels);
64-
if (class_exists(FlattenException::class)) {
65-
$notification->exception = $exception instanceof FlattenException ? $exception : FlattenException::createFromThrowable($exception);
66-
}
67-
$notification->exceptionAsString = $notification->computeExceptionAsString($exception);
68-
69-
return $notification;
61+
return (new self('', $channels))->exception($exception);
7062
}
7163

7264
/**
@@ -142,6 +134,22 @@ public function getEmoji(): string
142134
return $this->emoji ?: $this->getDefaultEmoji();
143135
}
144136

137+
/**
138+
* @return $this
139+
*/
140+
public function exception(\Throwable $exception): static
141+
{
142+
$parts = explode('\\', \get_class($exception));
143+
144+
$this->subject = sprintf('%s: %s', array_pop($parts), $exception->getMessage());
145+
if (class_exists(FlattenException::class)) {
146+
$this->exception = $exception instanceof FlattenException ? $exception : FlattenException::createFromThrowable($exception);
147+
}
148+
$this->exceptionAsString = $this->computeExceptionAsString($exception);
149+
150+
return $this;
151+
}
152+
145153
public function getException(): ?FlattenException
146154
{
147155
return $this->exception;

0 commit comments

Comments
 (0)