Passed
Push — master ( b100c0...62ec1b )
by Maurício
11:38 queued 13s
created

InsertEditColumn   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 55
rs 10
ccs 0
cts 16
cp 0
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 43 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin;
6
7
use function date;
8
use function md5;
9
use function preg_match;
10
use function preg_replace;
11
12
final class InsertEditColumn
13
{
14
    public readonly string|null $default;
15
    public readonly string $md5;
16
    /**
17
     * trueType contains only the type (stops at first bracket)
18
     */
19
    public readonly string $trueType;
20
    public readonly string $pmaType;
21
    public readonly int $length;
22
    public readonly bool $firstTimestamp;
23
24
    public function __construct(
25
        public readonly string $field,
26
        public readonly string $type,
27
        public readonly bool $isNull,
28
        public readonly string $key,
29
        string|null $default,
30
        public readonly string $extra,
31
        int $columnLength,
32
        public readonly bool $isBinary,
33
        public readonly bool $isBlob,
34
        public readonly bool $isChar,
35
        bool $insertMode,
36
    ) {
37
        if (
38
            $this->type === 'datetime'
39
            && ! $this->isNull
40
            && $default === null
41
            && $insertMode
42
        ) {
43
            $this->default = date('Y-m-d H:i:s');
0 ignored issues
show
Bug introduced by
The property default is declared read-only in PhpMyAdmin\InsertEditColumn.
Loading history...
44
        } else {
45
            $this->default = $default;
46
        }
47
48
        $this->md5 = md5($this->field);
0 ignored issues
show
Bug introduced by
The property md5 is declared read-only in PhpMyAdmin\InsertEditColumn.
Loading history...
49
        $this->trueType = preg_replace('@\(.*@s', '', $this->type);
0 ignored issues
show
Bug introduced by
The property trueType is declared read-only in PhpMyAdmin\InsertEditColumn.
Loading history...
50
        // length is unknown for geometry fields,
51
        // make enough space to edit very simple WKTs
52
        if ($columnLength === -1) {
53
            $columnLength = 30;
54
        }
55
56
        $this->length = preg_match('@float|double@', $this->type) ? 100 : $columnLength;
0 ignored issues
show
Bug introduced by
The property length is declared read-only in PhpMyAdmin\InsertEditColumn.
Loading history...
57
        $this->pmaType = match ($this->trueType) {
0 ignored issues
show
Bug introduced by
The property pmaType is declared read-only in PhpMyAdmin\InsertEditColumn.
Loading history...
58
            'set', 'enum' => $this->trueType,
59
            default => $this->type,
60
        };
61
        /**
62
         * TODO: This property is useless at the moment.
63
         * It seems like a long time ago before refactoring into classes,
64
         * this kept track of how many timestamps are in the table.
65
         */
66
        $this->firstTimestamp = $this->trueType === 'timestamp';
0 ignored issues
show
Bug introduced by
The property firstTimestamp is declared read-only in PhpMyAdmin\InsertEditColumn.
Loading history...
67
    }
68
}
69