AbstractQuery   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __unserialize() 0 3 1
A __construct() 0 5 1
A getAllowedInterfaces() 0 3 1
A getQueryType() 0 3 1
A __sleep() 0 3 1
A __wakeup() 0 3 1
A __serialize() 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\QueryException;
17
use Gears\DTO\ScalarPayloadBehaviour;
18
use Gears\Immutability\ImmutabilityBehaviour;
19
20
/**
21
 * Abstract immutable query.
22
 */
23
abstract class AbstractQuery implements Query
24
{
25
    use ImmutabilityBehaviour, ScalarPayloadBehaviour {
26
        ScalarPayloadBehaviour::__call insteadof ImmutabilityBehaviour;
27
    }
28
29
    /**
30
     * AbstractQuery 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 getQueryType(): string
45
    {
46
        return static::class;
47
    }
48
49
    /**
50
     * @return string[]
51
     */
52
    final public function __sleep(): array
53
    {
54
        throw new QueryException(\sprintf('Query "%s" cannot be serialized.', static::class));
55
    }
56
57
    final public function __wakeup(): void
58
    {
59
        throw new QueryException(\sprintf('Query "%s" cannot be unserialized.', static::class));
60
    }
61
62
    /**
63
     * @return array<string, mixed>
64
     */
65
    final public function __serialize(): array
66
    {
67
        throw new QueryException(\sprintf('Query "%s" cannot be serialized.', static::class));
68
    }
69
70
    /**
71
     * @param array<string, mixed> $data
72
     *
73
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
74
     */
75
    final public function __unserialize(array $data): void
76
    {
77
        throw new QueryException(\sprintf('Query "%s" cannot be unserialized.', static::class));
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     *
83
     * @return string[]
84
     */
85
    final protected function getAllowedInterfaces(): array
86
    {
87
        return [Query::class];
88
    }
89
}
90