Passed
Branch develop (f4dbb7)
by compolom
02:00
created

Fields::allias()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace Compolomus\LSQLQueryBuilder\System;
4
5
class Fields
6
{
7
    use Traits\Helper;
8
9
    private $name;
10
11
    private $allias = null;
12
13
    private $result = null;
14
15
    private $functionsList = [
16
        'COMPRESS',
17
        'MD5',
18
        'PASSWORD',
19
        'SHA',
20
        'SHA1',
21
        'UNCOMPRESS',
22
        'UNCOMPRESSED_LENGTH',
23
        'VALIDATE_PASSWORD_STRENGTH',
24
25
        'AVG',
26
        'BIT_AND',
27
        'BIT_OR',
28
        'BIT_XOR',
29
        'BIT_COUNT',
30
        'COUNT',
31
        'GROUP_CONCAT',
32
        'JSON_ARRAYAGG',
33
        'MAX',
34
        'MIN',
35
        'STD',
36
        'STDDEV',
37
        'STDDEV_POP',
38
        'STDDEV_SAMP',
39
        'SUM',
40
        'VAR_POP',
41
        'VAR_SAMP',
42
        'VARIANCE',
43
44
        'ASCII',
45
        'BIN',
46
        'ORD',
47
        'CHAR_LENGTH', // multibyte len
48
        'HEX',
49
        'OCT',
50
        'LCASE',
51
        'LOWER',
52
        'UCASE',
53
        'UPPER',
54
        'REVERSE',
55
        #'LOAD_FILE', // security
56
        'TRIM', // rtrim
57
        'LTRIM',
58
        'RTRIM',
59
60
        'ABS',
61
        'ACOS',
62
        'ASIN',
63
        'ATAN',
64
        'CEIL',
65
        'CEILING',
66
        'COS',
67
        'COT',
68
        'CRC32',
69
        'DEGREES',
70
        'EXP',
71
        'FLOOR',
72
        'LN',
73
        'LOG',
74
        'LOG2',
75
        'LOG10',
76
        'RADIANS',
77
        'ROUND',
78
        'SIGN',
79
        'SIN',
80
        'SQRT',
81
        'TAN',
82
83
        'DATE',
84
        'DAY',
85
        'DAYNAME',
86
        'DAYOFMONTH',
87
        'DAYOFWEEK',
88
        'DAYOFYEAR',
89
        'FROM_DAYS',
90
        'FROM_UNIXTIME',
91
        'HOUR',
92
        'LAST_DAY',
93
        'MICROSECOND',
94
        'MINUTE',
95
        'MONTH',
96
        'MONTHNAME',
97
        'QUARTER',
98
        'SECOND',
99
        'SEC_TO_TIME',
100
        'TIME',
101
        'TIME_TO_SEC',
102
        'TO_DAYS',
103
        'TO_SECONDS',
104
        'UNIX_TIMESTAMP',
105
        'WEEK',
106
        'WEEKDAY',
107
        'YEAR',
108
        'YEARWEEK',
109
        'WEEKOFYEAR',
110
    ];
111
112
    public function __construct(string $name)
113
    {
114
        $this->result = $this->name = $this->escapeField($name);
115
    }
116
117
    public function allias(string $alliasName): void
118
    {
119
        $this->allias = $this->escapeField($alliasName);
120
    }
121
122
    public function function(string $functionName): void
0 ignored issues
show
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
123
    {
124
        if (!in_array(strtoupper($functionName), $this->functionsList)) {
125
            throw new \InvalidArgumentException('MYSQL Функция ' . $functionName . ' не найдена |SELECT setFunction|');
126
        }
127
        $this->result = strtoupper($functionName) . '(' . $this->name . ')';
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $this.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
128
    }
129
130
    public function result(): string
131
    {
132
        return $this->result . (!is_null($this->allias) ? ' AS ' . $this->allias : '');
133
    }
134
}
135