HandleStoredEventJob   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 34
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 4 1
A __construct() 0 6 1
A tags() 0 6 2
A createForEvent() 0 4 1
1
<?php
2
3
namespace Spatie\EventProjector;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Queue\SerializesModels;
7
use Illuminate\Queue\InteractsWithQueue;
8
use Illuminate\Contracts\Queue\ShouldQueue;
9
10
final class HandleStoredEventJob implements ShouldQueue
11
{
12
    use InteractsWithQueue, Queueable, SerializesModels;
13
14
    /** @var \Spatie\EventProjector\StoredEvent */
15
    public $storedEvent;
16
17
    /** @var array */
18
    public $tags;
19
20
    public function __construct(StoredEvent $storedEvent, array $tags)
21
    {
22
        $this->storedEvent = $storedEvent;
23
24
        $this->tags = $tags;
25
    }
26
27
    public function handle(Projectionist $projectionist): void
28
    {
29
        $projectionist->handle($this->storedEvent);
30
    }
31
32
    public function tags(): array
33
    {
34
        return empty($this->tags)
35
            ? [$this->storedEvent->event_class]
36
            : $this->tags;
37
    }
38
39
    public static function createForEvent(StoredEvent $event, array $tags): self
40
    {
41
        return new static($event, $tags);
42
    }
43
}
44