Encryptable   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 1
f 0
dl 0
loc 24
ccs 0
cts 10
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttribute() 0 13 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 (\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