Passed
Push — master ( e1fd7c...ba32b0 )
by Igor
09:05 queued 14s
created

Settings   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 221
Duplicated Lines 0 %

Test Coverage

Coverage 88.14%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
eloc 48
c 4
b 0
f 1
dl 0
loc 221
ccs 52
cts 59
cp 0.8814
rs 10
wmc 26

22 Methods

Rating   Name   Duplication   Size   Complexity  
A isEnableHttpCompression() 0 3 1
A get() 0 6 2
A getSetting() 0 7 2
A https() 0 4 1
A max_execution_time() 0 4 1
A enableHttpCompression() 0 4 1
A is() 0 3 1
A session_id() 0 4 1
A isReadOnlyUser() 0 3 1
A getTimeOut() 0 3 1
A getSettings() 0 3 1
A database() 0 4 1
A readonly() 0 4 1
A makeSessionId() 0 4 1
A isHttps() 0 3 1
A setReadOnlyUser() 0 3 1
A getSessionId() 0 6 2
A set() 0 4 1
A apply() 0 7 2
A getDatabase() 0 3 1
A __construct() 0 11 1
A clear() 0 3 1
1
<?php
0 ignored issues
show
introduced by
Missing declare(strict_types=1).
Loading history...
2
3
namespace ClickHouseDB;
4
5
class Settings
6
{
7
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Settings::$settings with single line content, use one-line comment instead.
Loading history...
8
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Settings::$settings does not specify type hint for its items.
Loading history...
9
     */
10
    private $settings = [];
11
12
    private $_ReadOnlyUser = false;
0 ignored issues
show
introduced by
Property \ClickHouseDB\Settings::$_ReadOnlyUser does not have @var annotation for its value.
Loading history...
Coding Style introduced by
Member variable "_ReadOnlyUser" is not in valid camel caps format
Loading history...
13
14
    /**
15
     * Settings constructor.
0 ignored issues
show
introduced by
Documentation comment contains forbidden comment "Settings constructor.".
Loading history...
16
     */
17
    public function __construct()
18
    {
19
        $default = [
20
            'extremes' => false,
21
            'readonly' => true,
22
            'max_execution_time' => 20.0,
23
            'enable_http_compression' => 1,
24
            'https' => false,
25
        ];
26
27
        $this->settings = $default;
28
    }
29
30 68
    /**
31
     * @param string|int $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
32
     * @return mixed
33 68
     */
34
    public function get($key)
35
    {
36
        if (!$this->is($key)) {
0 ignored issues
show
introduced by
Expected 1 lines after "if", found 0.
Loading history...
Coding Style introduced by
Expected 1 space after NOT operator; 0 found
Loading history...
37
            return null;
38
        }
39
        return $this->settings[$key];
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
40 68
    }
41 68
42 68
    /**
43
     * @param string|int $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
44
     * @return bool
45
     */
46
    public function is($key)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Settings::is() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
47
    {
48 55
        return isset($this->settings[$key]);
49
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
50 55
51
52
    /**
53 55
     * @param string|int $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
54
     * @param mixed $value
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
55
     * @return $this
56
     */
57
    public function set($key, $value)
58
    {
59
        $this->settings[$key] = $value;
60 55
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
61
    }
62 55
63
    /**
64
     * @return mixed
65
     */
66
    public function getDatabase()
67
    {
68
        return $this->get('database');
69
    }
70
71 68
    /**
72
     * @param string $db
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
73 68
     * @return $this
74 68
     */
75
    public function database($db)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Settings::database() does not have native type hint for its parameter $db but it should be possible to add it based on @param annotation "string".
Loading history...
76
    {
77
        $this->set('database', $db);
78
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
79
    }
80 1
81
    /**
82 1
     * @return int
0 ignored issues
show
introduced by
Method \ClickHouseDB\Settings::getTimeOut() has useless @return annotation.
Loading history...
83
     */
84
    public function getTimeOut(): int
0 ignored issues
show
introduced by
Method \ClickHouseDB\Settings::getTimeOut() does not need documentation comment.
Loading history...
85
    {
86
        return intval($this->get('max_execution_time'));
0 ignored issues
show
introduced by
Function intval() should not be referenced via a fallback global name, but via a use statement.
Loading history...
87
    }
88
89 68
    /**
90
     * @return mixed|null
91 68
     */
92 68
    public function isEnableHttpCompression()
93
    {
94
        return $this->getSetting('enable_http_compression');
95
    }
96
97
    /**
98 46
     * @param bool|int $flag
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
99
     * @return $this
100 46
     */
101
    public function enableHttpCompression($flag)
102
    {
103
        $this->set('enable_http_compression', intval($flag));
0 ignored issues
show
introduced by
Function intval() should not be referenced via a fallback global name, but via a use statement.
Loading history...
104
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
105
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
106 45
107
108 45
    public function https($flag = true)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Settings::https() does not have parameter type hint nor @param annotation for its parameter $flag.
Loading history...
introduced by
Method \ClickHouseDB\Settings::https() does not have return type hint nor @return annotation for its return value.
Loading history...
109
    {
110
        $this->set('https', $flag);
111
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
112
    }
113
114
    public function isHttps()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Settings::isHttps() does not have return type hint nor @return annotation for its return value.
Loading history...
115 68
    {
116
        return $this->get('https');
117 68
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
118 68
119
120
    /**
121
     * @param int|bool $flag
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
122 1
     * @return $this
123
     */
124 1
    public function readonly($flag)
125 1
    {
126
        $this->set('readonly', $flag);
127
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
128 55
    }
129
130 55
    /**
131
     * @param string $session_id
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
132
     * @return $this
133
     */
134
    public function session_id($session_id)
0 ignored issues
show
Coding Style introduced by
Method name "Settings::session_id" is not in camel caps format
Loading history...
introduced by
Method \ClickHouseDB\Settings::session_id() does not have native type hint for its parameter $session_id but it should be possible to add it based on @param annotation "string".
Loading history...
Coding Style introduced by
The variable $session_id should be in camel caps format.
Loading history...
135
    {
136
        $this->set('session_id', $session_id);
0 ignored issues
show
Coding Style introduced by
The variable $session_id should be in camel caps format.
Loading history...
137
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
138
    }
139
140
    /**
141
     * @return mixed|bool
142
     */
143
    public function getSessionId()
144
    {
145
        if (empty($this->settings['session_id'])) {
0 ignored issues
show
introduced by
Expected 1 lines after "if", found 0.
Loading history...
146
            return false;
147
        }
148 2
        return $this->get('session_id');
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
149
    }
150 2
151 2
    /**
152
     * @return string|bool
153
     */
154
    public function makeSessionId()
155
    {
156
        $this->session_id(sha1(uniqid('', true)));
0 ignored issues
show
introduced by
Function sha1() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Function uniqid() should not be referenced via a fallback global name, but via a use statement.
Loading history...
157 46
        return $this->getSessionId();
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
158
    }
159 46
160 46
    /**
161
     *
162 2
     * max_execution_time - is integer in Seconds clickhouse source
0 ignored issues
show
introduced by
Expected 0 lines before first content, found 1.
Loading history...
163
     *
164
     * @param int $time
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Settings::max_execution_time() has useless @param annotation for parameter $time.
Loading history...
165
     * @return $this
166
     */
167
    public function max_execution_time(int $time)
0 ignored issues
show
Coding Style introduced by
Method name "Settings::max_execution_time" is not in camel caps format
Loading history...
168 2
    {
169
        $this->set('max_execution_time',$time);
170 2
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
171 2
    }
172
173
    /**
174
     * @return array
0 ignored issues
show
introduced by
@return annotation of method \ClickHouseDB\Settings::getSettings() does not specify type hint for items of its traversable return value.
Loading history...
175
     */
176
    public function getSettings()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Settings::getSettings() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
177
    {
178 2
        return $this->settings;
179
    }
180 2
181 2
    /**
182
     * @param array $settings_array
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@param annotation of method \ClickHouseDB\Settings::apply() does not specify type hint for items of its traversable parameter $settings_array.
Loading history...
183
     * @return $this
184
     */
185
    public function apply(array $settings_array)
0 ignored issues
show
Coding Style introduced by
The variable $settings_array should be in camel caps format.
Loading history...
186
    {
187 45
        foreach ($settings_array as $key => $value) {
0 ignored issues
show
Coding Style introduced by
The variable $settings_array should be in camel caps format.
Loading history...
188
            $this->set($key, $value);
189 45
        }
190
191
        return $this;
192
    }
193
194
    /**
195
     * @param int|bool $flag
196 1
     */
197
    public function setReadOnlyUser($flag):void
0 ignored issues
show
introduced by
There must be exactly one space between return type hint colon and return type hint.
Loading history...
198 1
    {
199 1
        $this->_ReadOnlyUser = $flag;
0 ignored issues
show
Coding Style introduced by
Member variable "_ReadOnlyUser" is not in valid camel caps format
Loading history...
200
    }
201
202 1
    /**
203
     * @return bool
0 ignored issues
show
introduced by
Method \ClickHouseDB\Settings::isReadOnlyUser() has useless @return annotation.
Loading history...
204
     */
205
    public function isReadOnlyUser():bool
0 ignored issues
show
introduced by
Method \ClickHouseDB\Settings::isReadOnlyUser() does not need documentation comment.
Loading history...
introduced by
There must be exactly one space between return type hint colon and return type hint.
Loading history...
206
    {
207
        return $this->_ReadOnlyUser;
0 ignored issues
show
Coding Style introduced by
Member variable "_ReadOnlyUser" is not in valid camel caps format
Loading history...
208
    }
209
210
    /**
211
     * @param string $name
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Settings::getSetting() has useless @param annotation for parameter $name.
Loading history...
212
     * @return mixed|null
213
     */
214
    public function getSetting(string $name)
215
    {
216 45
        if (!isset($this->settings[$name])) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after NOT operator; 0 found
Loading history...
217
            return null;
218 45
        }
219
220
        return $this->get($name);
221
    }
222
223
    public function clear():void
0 ignored issues
show
introduced by
There must be exactly one space between return type hint colon and return type hint.
Loading history...
224
    {
225 46
        $this->settings = [];
226
    }
227
}
228