TrackableEventCreationFailed   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A forEventClass() 0 15 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ReliqArts\Logistiq\Tracking\Exceptions;
6
7
use ReliqArts\Logistiq\Tracking\Contracts\Trackable;
8
use Throwable;
9
10
final class TrackableEventCreationFailed extends Exception
11
{
12
    protected const CODE = 5100;
13
14
    /**
15
     * @var string
16
     */
17
    private $eventClassName;
18
19
    /**
20
     * @param string         $eventClassName
21
     * @param Trackable      $trackable
22
     * @param null|Throwable $previous
23
     *
24
     * @return self
25
     */
26
    public static function forEventClass(
27
        string $eventClassName,
28
        Trackable $trackable,
29
        Throwable $previous = null
30
    ): self {
31
        $message = sprintf(
32
            'Failed to create and inflate event: `%s`,  with trackable: `%s`.',
33
            $eventClassName,
34
            $trackable->getIdentifier()
35
        );
36
37
        $instance = new self($message, static::CODE, $previous);
38
        $instance->eventClassName = $eventClassName;
39
40
        return $instance;
41
    }
42
}
43