Completed
Push — master ( 6bd7ef...0bedd7 )
by Julián
02:12
created

AbstractCommand::__unserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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 immutable serializable command.
22
 */
23
abstract class AbstractCommand implements Command
24
{
25
    use ImmutabilityBehaviour, ScalarPayloadBehaviour {
26
        ScalarPayloadBehaviour::__call insteadof ImmutabilityBehaviour;
27
    }
28
29
    /**
30
     * AbstractCommand constructor.
31
     *
32
     * @param mixed[] $parameters
33
     */
34
    final protected function __construct(array $parameters)
35
    {
36
        $this->assertImmutable();
37
38
        $this->setPayload($parameters);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getCommandType(): string
45
    {
46
        return static::class;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    final public static function reconstitute(array $parameters)
53
    {
54
        $commandClass = static::class;
55
56
        return new $commandClass($parameters);
57
    }
58
59
    /**
60
     * @return string[]
61
     */
62
    final public function __sleep(): array
63
    {
64
        throw new CommandException(\sprintf('Command "%s" cannot be serialized', static::class));
65
    }
66
67
    final public function __wakeup(): void
68
    {
69
        throw new CommandException(\sprintf('Command "%s" cannot be unserialized', static::class));
70
    }
71
72
    /**
73
     * @return array<string, mixed>
74
     */
75
    final public function __serialize(): array
76
    {
77
        throw new CommandException(\sprintf('Command "%s" cannot be serialized', static::class));
78
    }
79
80
    /**
81
     * @param array<string, mixed> $data
82
     *
83
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
84
     */
85
    final public function __unserialize(array $data): void
86
    {
87
        throw new CommandException(\sprintf('Command "%s" cannot be unserialized', static::class));
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     *
93
     * @return string[]
94
     */
95
    final protected function getAllowedInterfaces(): array
96
    {
97
        return [Command::class];
98
    }
99
}
100