DispatchException   A
last analyzed

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
/**
6
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
7
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
9
 *
10
 * Copyright (c) 2024 Mykhailo Shtanko [email protected]
11
 *
12
 * For the full copyright and license information, please view the LICENSE.MD
13
 * file that was distributed with this source code.
14
 */
15
16
namespace FRZB\Component\TransactionalMessenger\Exception;
17
18
use JetBrains\PhpStorm\Immutable;
19
use Symfony\Component\Console\Event\ConsoleSignalEvent;
20
21
#[Immutable]
22
final class DispatchException extends \LogicException
23
{
24
    private const MESSAGE_SIGNAL_CONSOLE_EVENT = 'Rollback transaction: Message was interrupted in "%s" command on signal';
25
26
    public static function fromSignal(ConsoleSignalEvent $event): self
27
    {
28
        $message = sprintf(self::MESSAGE_SIGNAL_CONSOLE_EVENT, $event->getCommand()->getName());
29
30
        return new self($message, $event->getHandlingSignal());
31
    }
32
33
    public static function fromThrowable(\Throwable $previous): self
34
    {
35
        return new self($previous->getMessage(), (int) $previous->getCode(), $previous);
36
    }
37
}
38