Encryptable::setAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 3
cp 0
rs 10
cc 2
nc 2
nop 2
crap 6
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 (\Throwable $exception) {
17
                $value = '';
18
            }
19
        }
20
21
        return $value;
22
    }
23
24
    public function setAttribute($key, $value)
25
    {
26
        if (in_array($key, $this->encryptable)) {
27
            $value = Crypt::encrypt($value);
28
        }
29
30
        return parent::setAttribute($key, $value);
31
    }
32
}
33