GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Cast   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 56
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handleNullValue() 0 7 2
A asEnum() 0 9 2
A __construct() 0 5 1
1
<?php
2
3
namespace Spatie\Enum\Laravel\Casts;
4
5
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
6
use Illuminate\Database\Eloquent\Model;
7
use Spatie\Enum\Enum;
8
use Spatie\Enum\Laravel\Exceptions\NotNullableEnumField as NotNullableEnumFieldAlias;
9
10
abstract class Cast implements CastsAttributes
11
{
12
    /** @var string|Enum */
13
    protected string $enumClass;
14
15
    protected bool $isNullable = false;
16
17
    /**
18
     * Cast constructor.
19
     * @param string $enumClass
20
     * @param string[] ...$options
21
     */
22
    public function __construct(string $enumClass, ...$options)
23
    {
24
        $this->enumClass = $enumClass;
25
26
        $this->isNullable = in_array('nullable', $options);
27
    }
28
29
    /**
30
     * @param int|string|\Spatie\Enum\Enum $value
31
     *
32
     * @return \Spatie\Enum\Enum
33
     *
34
     * @throws \TypeError
35
     * @throws \BadMethodCallException
36
     *
37
     * @see \Spatie\Enum\Enum::make()
38
     */
39
    protected function asEnum($value): Enum
40
    {
41
        if ($value instanceof Enum) {
42
            return $value;
43
        }
44
45
        return forward_static_call(
46
            [$this->enumClass, 'make'],
47
            $value
48
        );
49
    }
50
51
    /**
52
     * @param Model $model
53
     * @param string $key
54
     *
55
     * @return null
56
     *
57
     * @throws \Spatie\Enum\Laravel\Exceptions\NotNullableEnumField
58
     */
59
    protected function handleNullValue(Model $model, string $key)
60
    {
61
        if ($this->isNullable) {
62
            return null;
63
        }
64
65
        throw NotNullableEnumFieldAlias::make($key, get_class($model));
66
    }
67
}
68