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.
Passed
Pull Request — master (#44)
by Tom
09:24
created

Cast::handleNullValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 3
c 1
b 1
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 2
1
<?php
2
3
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
4
use Illuminate\Database\Eloquent\Model;
5
use Spatie\Enum\Enum;
6
use Spatie\Enum\Laravel\Exceptions\NotNullableEnumField as NotNullableEnumFieldAlias;
7
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)
53
    {
54
        if ($this->isNullable) {
55
            return null;
56
        }
57
58
        throw NotNullableEnumFieldAlias::make($key, get_class($model));
59
    }
60
}
61