-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSplEnumUnitTrait.php
98 lines (87 loc) · 1.99 KB
/
SplEnumUnitTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* Part of SplTypes package.
*
* (c) Adrien Loyant <donald_duck@team-df.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Ducks\Component\SplTypes;
/**
* SplEnumUnitTrait expose magic method in order to use an SplEnum class which implements SplUnitEnum.
*
* @phpstan-require-extends SplEnum
* @phpstan-require-implements SplUnitEnum
*
* @psalm-api
*/
trait SplEnumUnitTrait
{
/**
* Serialize object.
*
* @return mixed[]
*
* @phpstan-return array<string,mixed>
*/
public function __serialize(): array
{
$result = parent::__serialize();
$result['name'] = $this->name;
return $result;
}
/**
* Unserialize object.
*
* @param mixed[] $data
*
* @return void
*
* @phpstan-param array<string,mixed> $data
* @phpstan-return void
*/
public function __unserialize(array $data): void
{
parent::__unserialize($data);
$this->name = (string) $data['name'];
}
/**
* Instanciate an exported object.
*
* @param mixed[] $properties
*
* @return static
*
* @phpstan-param array<string,mixed> $properties
* @phpstan-return static
*
* @psalm-suppress UnsafeInstantiation
*/
public static function __set_state(array $properties): SplUnitEnum
{
/**
* @var static $object
*/
// @phpstan-ignore-next-line
$object = /** @scrutinizer ignore-call */ new static();
$object->name = (string) $properties['name'];
return $object;
}
/**
* Dumping object.
*
* @return string[]
*
* @phpstan-return array<string,mixed>
*
* @codeCoverageIgnore
*/
public function __debugInfo(): array
{
$result = parent::__debugInfo();
$result['name'] = $this->name;
return $result;
}
}