SchemaHelper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 85
c 0
b 0
f 0
dl 0
loc 139
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
B getAuditTableColumns() 0 87 1
A getAuditTableIndices() 0 29 1
A __construct() 0 2 1
1
<?php
2
3
namespace DH\DoctrineAuditBundle\Helper;
4
5
final class SchemaHelper
6
{
7
    private function __construct()
8
    {
9
    }
10
11
    /**
12
     * Return columns of audit tables.
13
     *
14
     * @return array
15
     */
16
    public static function getAuditTableColumns(): array
17
    {
18
        return [
19
            'id' => [
20
                'type' => DoctrineHelper::getDoctrineType('INTEGER'),
21
                'options' => [
22
                    'autoincrement' => true,
23
                    'unsigned' => true,
24
                ],
25
            ],
26
            'type' => [
27
                'type' => DoctrineHelper::getDoctrineType('STRING'),
28
                'options' => [
29
                    'notnull' => true,
30
                    'length' => 10,
31
                ],
32
            ],
33
            'object_id' => [
34
                'type' => DoctrineHelper::getDoctrineType('STRING'),
35
                'options' => [
36
                    'notnull' => true,
37
                ],
38
            ],
39
            'discriminator' => [
40
                'type' => DoctrineHelper::getDoctrineType('STRING'),
41
                'options' => [
42
                    'default' => null,
43
                    'notnull' => false,
44
                ],
45
            ],
46
            'transaction_hash' => [
47
                'type' => DoctrineHelper::getDoctrineType('STRING'),
48
                'options' => [
49
                    'notnull' => false,
50
                    'length' => 40,
51
                ],
52
            ],
53
            'diffs' => [
54
                'type' => DoctrineHelper::getDoctrineType('JSON'),
55
                'options' => [
56
                    'default' => null,
57
                    'notnull' => false,
58
                ],
59
            ],
60
            'blame_id' => [
61
                'type' => DoctrineHelper::getDoctrineType('STRING'),
62
                'options' => [
63
                    'default' => null,
64
                    'notnull' => false,
65
                ],
66
            ],
67
            'blame_user' => [
68
                'type' => DoctrineHelper::getDoctrineType('STRING'),
69
                'options' => [
70
                    'default' => null,
71
                    'notnull' => false,
72
                    'length' => 255,
73
                ],
74
            ],
75
            'blame_user_fqdn' => [
76
                'type' => DoctrineHelper::getDoctrineType('STRING'),
77
                'options' => [
78
                    'default' => null,
79
                    'notnull' => false,
80
                    'length' => 255,
81
                ],
82
            ],
83
            'blame_user_firewall' => [
84
                'type' => DoctrineHelper::getDoctrineType('STRING'),
85
                'options' => [
86
                    'default' => null,
87
                    'notnull' => false,
88
                    'length' => 100,
89
                ],
90
            ],
91
            'ip' => [
92
                'type' => DoctrineHelper::getDoctrineType('STRING'),
93
                'options' => [
94
                    'default' => null,
95
                    'notnull' => false,
96
                    'length' => 45,
97
                ],
98
            ],
99
            'created_at' => [
100
                'type' => DoctrineHelper::getDoctrineType('DATETIME_IMMUTABLE'),
101
                'options' => [
102
                    'notnull' => true,
103
                ],
104
            ],
105
        ];
106
    }
107
108
    /**
109
     * Return indices of an audit table.
110
     *
111
     * @param string $tablename
112
     *
113
     * @return array
114
     */
115
    public static function getAuditTableIndices(string $tablename): array
116
    {
117
        return [
118
            'id' => [
119
                'type' => 'primary',
120
            ],
121
            'type' => [
122
                'type' => 'index',
123
                'name' => 'type_'.md5($tablename).'_idx',
124
            ],
125
            'object_id' => [
126
                'type' => 'index',
127
                'name' => 'object_id_'.md5($tablename).'_idx',
128
            ],
129
            'discriminator' => [
130
                'type' => 'index',
131
                'name' => 'discriminator_'.md5($tablename).'_idx',
132
            ],
133
            'transaction_hash' => [
134
                'type' => 'index',
135
                'name' => 'transaction_hash_'.md5($tablename).'_idx',
136
            ],
137
            'blame_id' => [
138
                'type' => 'index',
139
                'name' => 'blame_id_'.md5($tablename).'_idx',
140
            ],
141
            'created_at' => [
142
                'type' => 'index',
143
                'name' => 'created_at_'.md5($tablename).'_idx',
144
            ],
145
        ];
146
    }
147
}
148