Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 21 | trait EnumSerializableTrait |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * The method will be defined by MabeEnum\Enum |
||
| 25 | * @return null|bool|int|float|string |
||
| 26 | */ |
||
| 27 | abstract public function getValue(); |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Serialized the value of the enumeration |
||
| 31 | * This will be called automatically on `serialize()` if the enumeration implements the `Serializable` interface |
||
| 32 | * @return string |
||
| 33 | */ |
||
| 34 | public function serialize() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Unserializes a given serialized value and push it into the current instance |
||
| 41 | * This will be called automatically on `unserialize()` if the enumeration implements the `Serializable` interface |
||
| 42 | * @param string $serialized |
||
| 43 | * @throws RuntimeException On an unknown or invalid value |
||
| 44 | * @throws LogicException On changing numeration value by calling this directly |
||
| 45 | */ |
||
| 46 | public function unserialize($serialized) |
||
| 74 | } |
||
| 75 |