Test Setup Failed
Push — develop ( a7c3b2...e2193c )
by Nikita
05:55 queued 10s
created

Encryptable   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttribute() 0 14 3
A setAttribute() 0 7 2
1
<?php
2
3
namespace Gameap\Traits;
4
5
use Illuminate\Support\Facades\Crypt;
6
7
trait Encryptable
8
{
9
    public function getAttribute($key)
10
    {
11
        $value = parent::getAttribute($key);
12
13
        if (in_array($key, $this->encryptable)) {
14
            try {
15
                $value = Crypt::decrypt($value);
16
            } catch (\Exception $exception) {
17
                $value = "";
18
            }
19
20
        }
21
22
        return $value;
23
    }
24
25
    public function setAttribute($key, $value)
26
    {
27
        if (in_array($key, $this->encryptable)) {
28
            $value = Crypt::encrypt($value);
29
        }
30
31
        return parent::setAttribute($key, $value);
32
    }
33
}