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

Encryptable::setAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
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
}