1 | <?php |
||
2 | |||
3 | namespace LeKoala\Encrypt; |
||
4 | |||
5 | /** |
||
6 | * This trait allow encryption for fields that don't |
||
7 | * require a blind index |
||
8 | */ |
||
9 | trait HasEncryption |
||
10 | { |
||
11 | use HasBaseEncryption; |
||
12 | |||
13 | /** |
||
14 | * prepValueForDB gets passed $this->value |
||
15 | * |
||
16 | * @param string $value |
||
17 | * @return string |
||
18 | */ |
||
19 | public function prepValueForDB($value) |
||
20 | { |
||
21 | if (!$value) { |
||
22 | if ($this->getNullifyEmpty() || $value === null) { |
||
23 | return null; |
||
24 | } |
||
25 | return ''; |
||
26 | } |
||
27 | // Don't encrypt twice |
||
28 | if (EncryptHelper::isEncrypted($value)) { |
||
29 | return $value; |
||
30 | } |
||
31 | $aad = $this->encryptionAad; |
||
32 | $encryptedValue = $this->getEncryptedField()->encryptValue($value, $aad); |
||
33 | return $encryptedValue; |
||
34 | } |
||
35 | |||
36 | public function setValue($value, $record = null, $markChanged = true) |
||
0 ignored issues
–
show
|
|||
37 | { |
||
38 | $this->setEncryptionAad($record); |
||
39 | |||
40 | // Return early if we keep encrypted value in memory |
||
41 | if (!EncryptHelper::getAutomaticDecryption()) { |
||
42 | $this->value = $value; |
||
43 | return $this; |
||
44 | } |
||
45 | |||
46 | // $markChanged is not used |
||
47 | // The value might come encrypted from the database |
||
48 | if ($value && EncryptHelper::isEncrypted($value)) { |
||
49 | $this->value = $this->decryptValue($value); |
||
50 | } else { |
||
51 | $this->value = $value; |
||
52 | } |
||
53 | return $this; |
||
54 | } |
||
55 | } |
||
56 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.