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