QueryTrait   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 14

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getEditFunctionNames() 0 16 10
A editFunctions() 0 9 4
1
<?php
2
3
namespace Lagdo\DbAdmin\Admin\Traits;
4
5
use Lagdo\DbAdmin\Driver\Entity\TableFieldEntity;
6
7
trait QueryTrait
8
{
9
    /**
10
     * @param TableFieldEntity $field
11
     * @param array $values First entries
12
     * @param bool $update
13
     *
14
     * @return string[]
15
     */
16
    private function getEditFunctionNames(TableFieldEntity $field, array $values, bool $update): array
17
    {
18
        $names = $values;
19
        foreach ($this->driver->editFunctions() as $key => $functions) {
20
            if (!$key || (!isset($this->utils->input->values['call']) && $update)) { // relative functions
21
                foreach ($functions as $pattern => $value) {
22
                    if (!$pattern || preg_match("~$pattern~", $field->type)) {
23
                        $names[] = $value;
24
                    }
25
                }
26
            }
27
            if ($key && !preg_match('~set|blob|bytea|raw|file|bool~', $field->type)) {
28
                $names[] = 'SQL';
29
            }
30
        }
31
        return $names;
32
    }
33
34
    /**
35
     * Functions displayed in edit form
36
     *
37
     * @param TableFieldEntity $field Single field from fields()
38
     *
39
     * @return array
40
     */
41
    public function editFunctions(TableFieldEntity $field): array
42
    {
43
        $update = isset($this->utils->input->values['select']); // || $this->where([]);
44
        if ($field->autoIncrement && !$update) {
45
            return [$this->utils->trans->lang('Auto Increment')];
46
        }
47
48
        $names = $field->null ? ['NULL', ''] : [''];
49
        return $this->getEditFunctionNames($field, $names, $update);
50
    }
51
}
52