Passed
Push — master ( 20c7a2...113399 )
by Stephen
02:33 queued 01:07
created

NullableIntArrayCast   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 22
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
4
namespace Sfneal\Casts;
5
6
use Vkovic\LaravelCustomCasts\CustomCastBase;
7
8
class NullableIntArrayCast extends CustomCastBase
9
{
10
    /**
11
     * json_decode the $value
12
     *
13
     * @param $value
14
     * @return string
15
     */
16
    public function setAttribute($value)
17
    {
18
        return !is_null($value) ? json_encode(array_map('intval', $value)) : null;
19
    }
20
21
    /**
22
     * json_encode the $value or return null
23
     *
24
     * @param $value
25
     * @return string
26
     */
27
    public function castAttribute($value)
28
    {
29
        return json_decode($value, true);
30
    }
31
}
32