AbstractDTO::__unserialize()   A
last analyzed

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
 * dto (https://github.com/phpgears/dto).
5
 * General purpose immutable Data Transfer Objects for PHP.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/dto
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\DTO;
15
16
use Gears\DTO\Exception\DTOException;
17
use Gears\Immutability\ImmutabilityBehaviour;
18
19
/**
20
 * Abstract immutable Data Transfer Object.
21
 */
22
abstract class AbstractDTO implements DTO
23
{
24
    use ImmutabilityBehaviour, PayloadBehaviour {
25
        PayloadBehaviour::__call insteadof ImmutabilityBehaviour;
26
    }
27
28
    /**
29
     * AbstractDTO constructor.
30
     *
31
     * @param array<string, mixed> $parameters
32
     */
33
    final protected function __construct(array $parameters)
34
    {
35
        $this->assertImmutable();
36
37
        $this->setPayload($parameters);
38
    }
39
40
    /**
41
     * @return string[]
42
     */
43
    final public function __sleep(): array
44
    {
45
        throw new DTOException(\sprintf('DTO "%s" cannot be serialized.', static::class));
46
    }
47
48
    final public function __wakeup(): void
49
    {
50
        throw new DTOException(\sprintf('DTO "%s" cannot be unserialized.', static::class));
51
    }
52
53
    /**
54
     * @return array<string, mixed>
55
     */
56
    final public function __serialize(): array
57
    {
58
        throw new DTOException(\sprintf('DTO "%s" cannot be serialized.', static::class));
59
    }
60
61
    /**
62
     * @param array<string, mixed> $data
63
     *
64
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
65
     */
66
    final public function __unserialize(array $data): void
67
    {
68
        throw new DTOException(\sprintf('DTO "%s" cannot be unserialized.', static::class));
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     *
74
     * @return string[]
75
     */
76
    final protected function getAllowedInterfaces(): array
77
    {
78
        return [DTO::class];
79
    }
80
}
81