Passed
Push — main ( 207cb8...b79353 )
by Fractal
12:49
created

DispatchException::fromThrowable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\TransactionalMessenger\Exception;
6
7
use JetBrains\PhpStorm\Immutable;
8
use Symfony\Component\Console\Event\ConsoleSignalEvent;
9
10
#[Immutable]
11
final class DispatchException extends \LogicException
12
{
13
    private const MESSAGE_SIGNAL_CONSOLE_EVENT = 'Rollback transaction: Message was interrupted in "%s" command on signal';
14
15
    public static function fromSignal(ConsoleSignalEvent $event): self
16
    {
17
        $message = sprintf(self::MESSAGE_SIGNAL_CONSOLE_EVENT, $event->getCommand());
18
19
        return new self($message, $event->getHandlingSignal());
20
    }
21
22
    public static function fromThrowable(\Throwable $previous): self
23
    {
24
        return new self($previous->getMessage(), (int) $previous->getCode(), $previous);
25
    }
26
}
27