Skip to content

Commit 10f9fb5

Browse files
committed
Add __unserialize method
1 parent b9edd18 commit 10f9fb5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/FakeEnum.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,25 @@ public function __wakeup()
106106
}
107107
}
108108

109+
/**
110+
* This method exists only for the compatibility reason when deserializing a previously serialized version
111+
* that didn't have the key property.
112+
*
113+
* @param array $data Data to unserialize from.
114+
* @psalm-param array $data
115+
*/
116+
public function __unserialize(array $data): void
117+
{
118+
/** @psalm-suppress DocblockTypeContradiction key can be null when deserializing an enum without the key */
119+
if ($this->key === null) {
120+
/**
121+
* @psalm-suppress InaccessibleProperty key is not readonly as marked by psalm
122+
* @psalm-suppress PossiblyFalsePropertyAssignmentValue deserializing a case that was removed
123+
*/
124+
$this->key = static::search($this->value);
125+
}
126+
}
127+
109128
/**
110129
* Create a new enum instance from a value.
111130
*

0 commit comments

Comments
 (0)