Completed
Push — master ( bebec0...d8c5eb )
by Freek
13s
created

HandleStoredEventJob::createForEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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
use Spatie\EventProjector\Models\StoredEvent;
10
11
class HandleStoredEventJob implements ShouldQueue
12
{
13
    use InteractsWithQueue, Queueable, SerializesModels;
14
15
    /** @var \Spatie\EventProjector\Models\StoredEvent */
16
    public $storedEvent;
17
18
    /** @var array */
19
    public $tags;
20
21
    public function __construct(StoredEvent $storedEvent, array $tags)
22
    {
23
        $this->storedEvent = $storedEvent;
24
        $this->tags = $tags;
25
    }
26
27
    public function handle(Projectionist $projectionist)
28
    {
29
        $projectionist->handle($this->storedEvent);
30
    }
31
32
    public function tags(): array
33
    {
34
        if (empty($this->tags)) {
35
            return [
36
                $this->storedEvent['event_class'],
37
            ];
38
        }
39
40
        return $this->tags;
41
    }
42
43
    public static function createForEvent(StoredEvent $event, array $tags)
44
    {
45
        return new static($event, $tags);
46
    }
47
}
48