HasEvents   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 1
Metric Value
eloc 7
c 4
b 1
f 1
dl 0
loc 29
ccs 7
cts 7
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A withEvents() 0 5 1
A fireEvent() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\EnhancedPipeline\Traits;
6
7
trait HasEvents
8
{
9
    /**
10
     * Determines whether pipeline uses events.
11
     */
12
    protected bool $useEvents = false;
13
14
    /**
15
     * Enable events in pipeline.
16
     */
17 5
    public function withEvents(): static
18
    {
19 5
        $this->useEvents = true;
20
21 5
        return $this;
22
    }
23
24
    /**
25
     * Fire the event if enabled.
26
     *
27
     * @param  mixed  ...$params
28
     */
29 31
    protected function fireEvent(string $event, ...$params): void
30
    {
31 31
        if (! $this->useEvents) {
32 26
            return;
33
        }
34
35 5
        event(new $event(...$params));
36
    }
37
}
38