HasEvents::fireEvent()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
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