ParameterEventDiscriminator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A shouldEnqueue() 0 4 3
1
<?php
2
3
/*
4
 * event-async (https://github.com/phpgears/event-async).
5
 * Async decorator for Event bus.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/event-async
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\Event\Async\Discriminator;
15
16
use Gears\Event\Event;
17
18
final class ParameterEventDiscriminator implements EventDiscriminator
19
{
20
    /**
21
     * Event parameter name.
22
     *
23
     * @var string
24
     */
25
    private $parameter;
26
27
    /**
28
     * Expected event parameter value.
29
     *
30
     * @var mixed|null
31
     */
32
    private $value;
33
34
    /**
35
     * ParameterEventDiscriminator constructor.
36
     *
37
     * @param string     $parameter
38
     * @param mixed|null $value
39
     */
40
    public function __construct(string $parameter, $value = null)
41
    {
42
        $this->parameter = $parameter;
43
        $this->value = $value;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function shouldEnqueue(Event $event): bool
50
    {
51
        return $event->has($this->parameter)
52
            && ($this->value === null || $event->get($this->parameter) === $this->value);
53
    }
54
}
55