AbstractEmptyCommand   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
eloc 12
c 1
b 0
f 1
dl 0
loc 73
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getCommandType() 0 3 1
A getAllowedInterfaces() 0 3 1
A __unserialize() 0 3 1
A reconstitute() 0 5 1
A __wakeup() 0 3 1
A __construct() 0 3 1
A __serialize() 0 3 1
A __sleep() 0 3 1
1
<?php
2
3
/*
4
 * cqrs (https://github.com/phpgears/cqrs).
5
 * CQRS base.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/cqrs
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\CQRS;
15
16
use Gears\CQRS\Exception\CommandException;
17
use Gears\DTO\ScalarPayloadBehaviour;
18
use Gears\Immutability\ImmutabilityBehaviour;
19
20
/**
21
 * Abstract empty immutable serializable command.
22
 */
23
abstract class AbstractEmptyCommand implements Command
24
{
25
    use ImmutabilityBehaviour, ScalarPayloadBehaviour {
26
        ScalarPayloadBehaviour::__call insteadof ImmutabilityBehaviour;
27
    }
28
29
    /**
30
     * AbstractEmptyCommand constructor.
31
     */
32
    final protected function __construct()
33
    {
34
        $this->assertImmutable();
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getCommandType(): string
41
    {
42
        return static::class;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     *
48
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
49
     */
50
    final public static function reconstitute(array $parameters)
51
    {
52
        $commandClass = static::class;
53
54
        return new $commandClass();
55
    }
56
57
    /**
58
     * @return array<string, mixed>
59
     */
60
    final public function __serialize(): array
61
    {
62
        throw new CommandException(\sprintf('Command "%s" cannot be serialized.', static::class));
63
    }
64
65
    /**
66
     * @param array<string, mixed> $data
67
     *
68
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
69
     */
70
    final public function __unserialize(array $data): void
71
    {
72
        throw new CommandException(\sprintf('Command "%s" cannot be unserialized.', static::class));
73
    }
74
75
    /**
76
     * @return string[]
77
     */
78
    final public function __sleep(): array
79
    {
80
        throw new CommandException(\sprintf('Command "%s" cannot be serialized.', static::class));
81
    }
82
83
    final public function __wakeup(): void
84
    {
85
        throw new CommandException(\sprintf('Command "%s" cannot be unserialized.', static::class));
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     *
91
     * @return string[]
92
     */
93
    final protected function getAllowedInterfaces(): array
94
    {
95
        return [Command::class];
96
    }
97
}
98