| Total Complexity | 5 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 8 | abstract class Cast implements CastsAttributes |
||
| 9 | { |
||
| 10 | /** @var string|Enum */ |
||
| 11 | protected string $enumClass; |
||
| 12 | |||
| 13 | protected bool $isNullable = false; |
||
| 14 | |||
| 15 | public function __construct(string $enumClass, ...$options) |
||
| 16 | { |
||
| 17 | $this->enumClass = $enumClass; |
||
| 18 | |||
| 19 | $this->isNullable = in_array('nullable', $options); |
||
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param int|string|\Spatie\Enum\Enum $value |
||
| 24 | * |
||
| 25 | * @return \Spatie\Enum\Enum |
||
| 26 | * |
||
| 27 | * @throws \TypeError |
||
| 28 | * @throws \BadMethodCallException |
||
| 29 | * |
||
| 30 | * @see \Spatie\Enum\Enum::make() |
||
| 31 | */ |
||
| 32 | protected function asEnum($value): Enum |
||
| 33 | { |
||
| 34 | if ($value instanceof Enum) { |
||
| 35 | return $value; |
||
| 36 | } |
||
| 37 | |||
| 38 | return forward_static_call( |
||
| 39 | [$this->enumClass, 'make'], |
||
| 40 | $value |
||
| 41 | ); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param Model $model |
||
| 46 | * @param string $key |
||
| 47 | * |
||
| 48 | * @return null |
||
| 49 | * |
||
| 50 | * @throws \Spatie\Enum\Laravel\Exceptions\NotNullableEnumField |
||
| 51 | */ |
||
| 52 | protected function handleNullValue(Model $model, string $key) |
||
| 59 | } |
||
| 60 | } |
||
| 61 |