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.
Completed
Pull Request — master (#44)
by Tom
07:55
created

EnumCollectionCast::asEnums()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Spatie\Enum\Laravel\Casts;
4
5
use Illuminate\Support\Arr;
6
use Spatie\Enum\Enum;
7
8
class EnumCollectionCast extends EnumCast
9
{
10
    /**
11
     * @param \Illuminate\Database\Eloquent\Model $model
12
     * @param string $key
13
     * @param int[]|string[]|null|mixed $value
14
     * @param array $attributes
15
     *
16
     * @return \Spatie\Enum\Enum[]|null
17
     *
18
     * @throws \BadMethodCallException
19
     * @throws \Spatie\Enum\Laravel\Exceptions\NotNullableEnumField
20
     */
21
    public function get($model, string $key, $value, array $attributes)
22
    {
23
        if (is_null($value)) {
24
            return $this->handleNullValue($model, $key);
25
        }
26
27
        return $this->asEnums(
28
            Arr::wrap(json_decode($value, true))
29
        );
30
    }
31
32
    /**
33
     * @param \Illuminate\Database\Eloquent\Model $model
34
     * @param string $key
35
     * @param int[]|string[]|\Spatie\Enum\Enum[]|null|mixed $value
36
     * @param array $attributes
37
     *
38
     * @return string|null
39
     */
40
    public function set($model, string $key, $value, array $attributes)
41
    {
42
        if (is_null($value)) {
43
            return $this->handleNullValue($model, $key);
44
        }
45
46
        return json_encode($this->asEnums(Arr::wrap($value)));
47
    }
48
49
    /**
50
     * @param int[]|string[]|\Spatie\Enum\Enum[] $values
51
     *
52
     * @return \Spatie\Enum\Enum[]
53
     *
54
     * @throws \BadMethodCallException
55
     */
56
    protected function asEnums(array $values): array
57
    {
58
        return array_map([$this, 'asEnum'], $values);
59
    }
60
}
61