AESEncrypted   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A set() 0 8 2
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