ConfigEntity   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 171
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 36
c 2
b 0
f 0
dl 0
loc 171
rs 10
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setTypes() 0 5 2
A __construct() 0 4 1
A onActions() 0 3 1
A options() 0 22 5
1
<?php
2
3
namespace Lagdo\DbAdmin\Driver\Entity;
4
5
use Lagdo\DbAdmin\Driver\Utils\TranslatorInterface;
6
7
use function trim;
8
use function array_keys;
9
use function array_merge;
10
use function array_key_exists;
11
use function explode;
12
13
class ConfigEntity
14
{
15
    /**
16
     * @var string
17
     */
18
    public $jush = '';
19
20
    /**
21
     * @var string
22
     */
23
    public $version = '4.8.1-dev';
24
25
    /**
26
     * @var array
27
     */
28
    public $drivers = [];
29
30
    /**
31
     * @var array
32
     */
33
    public $types = [];
34
35
    /**
36
     * @var array
37
     */
38
    public $features = [];
39
40
    /**
41
     * @var array
42
     */
43
    public $structuredTypes = [];
44
45
    /**
46
     * @var array
47
     */
48
    public $unsigned = [];
49
50
    /**
51
     * @var array
52
     */
53
    public $operators = [];
54
55
    /**
56
     * @var array
57
     */
58
    public $functions = [];
59
60
    /**
61
     * @var array
62
     */
63
    public $grouping = [];
64
65
    /**
66
     * @var array
67
     */
68
    public $editFunctions = [];
69
70
    /**
71
     * @var array
72
     */
73
    public $options;
74
75
    /**
76
     * From bootstrap.inc.php
77
     * /// used in foreignKeys()
78
     * @var string
79
     */
80
    public $actions = 'RESTRICT|NO ACTION|CASCADE|SET NULL|SET DEFAULT';
81
82
    /**
83
     * // not point, not interval
84
     * @var string
85
     */
86
    public $numberRegex = '((?<!o)int(?!er)|numeric|real|float|double|decimal|money)';
87
88
    /**
89
     * From index.php
90
     * @var string
91
     */
92
    public $inout = 'IN|OUT|INOUT';
93
94
    /**
95
     * From index.php
96
     * @var string
97
     */
98
    public $enumLength = "'(?:''|[^'\\\\]|\\\\.)*'";
99
100
    /**
101
     * The current database name
102
     *
103
     * @var string
104
     */
105
    public $database = '';
106
107
    /**
108
     * The current schema name
109
     *
110
     * @var string
111
     */
112
    public $schema = '';
113
114
    /**
115
     * @var TranslatorInterface
116
     */
117
    public $trans;
118
119
    /**
120
     * The constructor
121
     *
122
     * @param TranslatorInterface $trans
123
     * @param array $options
124
     */
125
    public function __construct(TranslatorInterface $trans, array $options)
126
    {
127
        $this->trans = $trans;
128
        $this->options = $options;
129
    }
130
131
    /**
132
     * Set the supported types
133
     *
134
     * @param array $types
135
     *
136
     * @return void
137
     */
138
    public function setTypes(array $types)
139
    {
140
        foreach ($types as $group => $typeGroup) {
141
            $this->structuredTypes[$this->trans->lang($group)] = array_keys($typeGroup);
142
            $this->types = array_merge($this->types, $typeGroup);
143
        }
144
    }
145
146
    /**
147
     * Get the driver options
148
     *
149
     * @param string $name The option name
150
     * @param mixed $default
151
     *
152
     * @return mixed
153
     */
154
    public function options(string $name = '', $default = '')
155
    {
156
        if (!($name = trim($name))) {
157
            return $this->options;
158
        }
159
        if (array_key_exists($name, $this->options)) {
160
            return $this->options[$name];
161
        }
162
        if ($name === 'server') {
163
            $server = $this->options['host'] ?? '';
164
            $port = $this->options['port'] ?? ''; // Optional
165
            // Append the port to the host if it is defined.
166
            if (($port)) {
167
                $server .= ":$port";
168
            }
169
            return $server;
170
        }
171
        // if ($name === 'ssl') {
172
        //     return false; // No SSL options yet
173
        // }
174
        // Option not found
175
        return $default;
176
    }
177
178
    /**
179
     * @return array
180
     */
181
    public function onActions()
182
    {
183
        return explode('|', $this->actions);
184
    }
185
}
186