ParameterCommandDiscriminator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldEnqueue() 0 4 3
A __construct() 0 4 1
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