Passed
Push — master ( 347e4e...1a0023 )
by Dominic
03:19
created

Encryptable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 5
dl 0
loc 25
rs 10
c 2
b 1
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setValueAttribute() 0 6 2
A getValueAttribute() 0 3 2
1
<?php
2
3
namespace tbclla\Revolut\Traits;
4
5
use Illuminate\Support\Facades\Crypt;
6
7
trait Encryptable
8
{
9
	/**
10
	 * Set the value attribute
11
	 *
12
	 * @param string $value
13
	 * @return void
14
	 */
15
	public function setValueAttribute(string $value)
16
	{
17
		$encrypt = config('revolut.encrypt_tokens', true);
18
		
19
		$this->attributes['value'] = $encrypt ? encrypt($value) : $value;
0 ignored issues
show
Bug Best Practice introduced by
The property attributes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
20
		$this->attributes['is_encrypted'] = $encrypt;
21
	}
22
23
	/**
24
	 * Get the value attribute.
25
	 * 
26
	 * @param  string  $value
27
	 * @return string
28
	 */
29
	public function getValueAttribute(string $value)
30
	{
31
		return $this->is_encrypted ? decrypt($value) : $value;
32
	}
33
}
34