Encryptable::getAttribute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 7
c 1
b 1
f 0
dl 0
loc 13
ccs 0
cts 6
cp 0
rs 10
cc 3
nc 3
nop 1
crap 12
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