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
08:16 queued 05:38
created

Cast::handleNullValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
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
    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)
55
    {
56
        if ($this->isNullable) {
57
            return null;
58
        }
59
60
        throw NotNullableEnumFieldAlias::make($key, get_class($model));
61
    }
62
}
63