Test_EncryptedModel   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 6
Bugs 1 Features 2
Metric Value
wmc 3
eloc 26
c 6
b 1
f 2
dl 0
loc 64
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A writeBaseRecord() 0 5 1
A getField() 0 3 1
A setField() 0 3 1
1
<?php
2
3
namespace LeKoala\Encrypt\Test;
4
5
use SilverStripe\Assets\File;
6
use SilverStripe\Dev\TestOnly;
7
use SilverStripe\ORM\DataObject;
8
use SilverStripe\Security\Member;
9
use LeKoala\Encrypt\EncryptedFile;
10
use LeKoala\Encrypt\EncryptedDBJson;
11
use LeKoala\Encrypt\EncryptedDBText;
12
use LeKoala\Encrypt\EncryptedDBField;
13
use LeKoala\Encrypt\EncryptedDBVarchar;
14
use LeKoala\Encrypt\HasEncryptedFields;
15
use ParagonIE\CipherSweet\JsonFieldMap;
16
use LeKoala\Encrypt\EncryptedDBHTMLText;
17
use LeKoala\Encrypt\EncryptedNumberField;
18
use LeKoala\Encrypt\EncryptHelper;
19
20
/**
21
 * A test model for our encryption
22
 *
23
 * @property string $Name
24
 * @property string $MyText
25
 * @property string $MyHTMLText
26
 * @property string $MyVarchar
27
 * @property string $MyNumber
28
 * @property string $MyVarcharWithIndex
29
 * @property string $MyJson
30
 * @property string $MyEncryptedJson
31
 * @property int $RegularFileID
32
 * @property int $EncryptedFileID
33
 */
34
class Test_EncryptedModel extends DataObject implements TestOnly
35
{
36
    use HasEncryptedFields;
37
38
    /**
39
     * @var string
40
     */
41
    private static $table_name = 'EncryptedModel';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
42
43
    /**
44
     * @var array<string,string>
45
     */
46
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
47
        "Name" => 'Varchar',
48
        "MyText" => EncryptedDBText::class,
49
        "MyHTMLText" => EncryptedDBHTMLText::class,
50
        "MyVarchar" => EncryptedDBVarchar::class,
51
        "MyNumber" => EncryptedNumberField::class . '(["output_size" => 4, "domain_size" => 10])',
52
        "MyIndexedVarchar" => EncryptedDBField::class,
53
        "MyNullIndexedVarchar" => EncryptedDBField::class,
54
        "MyJson" => EncryptedDBJson::class,
55
        "MyEncryptedJson" => EncryptedDBJson::class . "(['map' => '7551830f{\"fields\":{\"$6e616d65\":\"string\",\"$616374697665\":\"bool\",\"$616765\":\"int\"}}'])",
56
    ];
57
58
    /**
59
     * @var array<string,string>
60
     */
61
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
62
        "RegularFile" => File::class,
63
        // We use regular File class for encrypted files to keep only one table
64
        "EncryptedFile" => File::class,
65
        "EncryptedFileClass" => EncryptedFile::class,
66
        "Member" => Member::class,
67
    ];
68
69
    /**
70
     * @var array<string,mixed>
71
     */
72
    private static $indexes = [
0 ignored issues
show
introduced by
The private property $indexes is not used, and could be removed.
Loading history...
73
        'MyIndexedVarcharBlindIndex' => true,
74
        'MyNumberBlindIndex' => true,
75
        'MyNumberLastFourBlindIndex' => true,
76
    ];
77
78
    /**
79
     * @param string $baseTable
80
     * @param string $now
81
     * @return void
82
     */
83
    protected function writeBaseRecord($baseTable, $now)
84
    {
85
        parent::writeBaseRecord($baseTable, $now);
86
        // After base record is written, we have an ID and therefore AAD has changed
87
        $this->resetFieldValues();
88
    }
89
90
    public function getField($field)
91
    {
92
        return $this->getEncryptedField($field);
93
    }
94
95
    public function setField($fieldName, $val)
96
    {
97
        return $this->setEncryptedField($fieldName, $val);
98
    }
99
}
100