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

DispatchException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 1
b 0
f 0
dl 0
loc 15
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromThrowable() 0 3 1
A fromSignal() 0 5 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