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

Encryptable::setValueAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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