ParameterCommandDiscriminator::shouldEnqueue()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 2
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
/*
4
 * cqrs-async (https://github.com/phpgears/cqrs-async).
5
 * Async decorator for CQRS command bus.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/cqrs-async
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\CQRS\Async\Discriminator;
15
16
use Gears\CQRS\Command;
17
18
final class ParameterCommandDiscriminator implements CommandDiscriminator
19
{
20
    /**
21
     * Command parameter name.
22
     *
23
     * @var string
24
     */
25
    private $parameter;
26
27
    /**
28
     * Expected command parameter value.
29
     *
30
     * @var mixed|null
31
     */
32
    private $value;
33
34
    /**
35
     * ParameterCommandDiscriminator 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(Command $command): bool
50
    {
51
        return $command->has($this->parameter)
52
            && ($this->value === null || $command->get($this->parameter) === $this->value);
53
    }
54
}
55