AESEncrypted::set()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 4
1
<?php
2
3
namespace RichardStyles\EloquentAES\Casts;
4
5
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
6
use RichardStyles\EloquentAES\EloquentAESFacade as EloquentAES;
7
8
class AESEncrypted implements CastsAttributes
9
{
10
    /**
11
     * Cast the given value and decrypt
12
     *
13
     * @param  \Illuminate\Database\Eloquent\Model  $model
14
     * @param  string  $key
15
     * @param  mixed  $value
16
     * @param  array  $attributes
17
     * @return array
18
     */
19
    public function get($model, $key, $value, $attributes)
20
    {
21
        if (is_null($value)) {
22
            return $value;
23
        }
24
        
25
        return EloquentAES::decrypt($value);
26
    }
27
28
    /**
29
     * Prepare the given value for storage.
30
     *
31
     * @param  \Illuminate\Database\Eloquent\Model  $model
32
     * @param  string  $key
33
     * @param  mixed  $value
34
     * @param  array  $attributes
35
     * @return string
36
     */
37
    public function set($model, $key, $value, $attributes)
38
    {
39
        if (is_null($value)) {
40
            return $value;
41
        }
42
        
43
        return EloquentAES::encrypt($value);
44
    }
45
}
46