NullableIntArrayCast   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
eloc 3
c 4
b 1
f 0
dl 0
loc 24
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setAttribute() 0 3 2
A castAttribute() 0 3 1
1
<?php
2
3
namespace Sfneal\Casts;
4
5
use Vkovic\LaravelCustomCasts\CustomCastBase;
6
7
class NullableIntArrayCast extends CustomCastBase
8
{
9
    /**
10
     * Cast the $value as an array of integer values.
11
     *
12
     *  - set to null if an empty array or null value is passed
13
     *
14
     * @param  $value
15
     * @return string
16
     */
17
    public function setAttribute($value): ?string
18
    {
19
        return ! is_null($value) ? json_encode(array_map('intval', $value)) : null;
20
    }
21
22
    /**
23
     * Retrieve an array of values.
24
     *
25
     * @param  $value
26
     * @return array
27
     */
28
    public function castAttribute($value): ?array
29
    {
30
        return json_decode($value, true);
31
    }
32
}
33