Settings   A
last analyzed

Complexity

Total Complexity 25

Size/Duplication

Total Lines 228
Duplicated Lines 0 %

Test Coverage

Coverage 87.1%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 50
dl 0
loc 228
ccs 54
cts 62
cp 0.871
rs 10
c 4
b 0
f 0
wmc 25

21 Methods

Rating   Name   Duplication   Size   Complexity  
A isEnableHttpCompression() 0 3 1
A enableHttpCompression() 0 4 1
A is() 0 3 1
A session_id() 0 4 1
A getTimeOut() 0 3 1
A database() 0 4 1
A isHttps() 0 3 1
A get() 0 6 2
A https() 0 4 1
A getDatabase() 0 3 1
A makeSessionId() 0 4 1
A getSessionId() 0 6 2
A getSetting() 0 7 2
A apply() 0 7 2
A isReadOnlyUser() 0 3 1
A setReadOnlyUser() 0 3 1
A set() 0 4 1
A max_execution_time() 0 4 1
A getSettings() 0 3 1
A readonly() 0 4 1
A __construct() 0 12 1
1
<?php
0 ignored issues
show
introduced by
Missing declare(strict_types=1).
Loading history...
2
3
namespace ClickHouseDB;
4
5
use ClickHouseDB\Transport\Http;
6
7
class Settings
8
{
9
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Settings::$client with single line content, use one-line comment instead.
Loading history...
10
     * @var Http
11
     */
12
    private $client = null;
13
14
    /**
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...
15
     * @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...
16
     */
17
    private $settings = [];
18
19
    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...
20
21
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Settings::$_isHttps with single line content, use one-line comment instead.
Loading history...
22
     * @var bool
23
     */
24
    private $_isHttps = false;
0 ignored issues
show
introduced by
The private property $_isHttps is not used, and could be removed.
Loading history...
25
26
    /**
27
     * Settings constructor.
0 ignored issues
show
introduced by
Documentation comment contains forbidden comment "Settings constructor.".
Loading history...
28
     * @param Http $client
0 ignored issues
show
introduced by
Expected 1 lines between description and annotations, found 0.
Loading history...
introduced by
Method \ClickHouseDB\Settings::__construct() has useless @param annotation for parameter $client.
Loading history...
29
     */
30 68
    public function __construct(Http $client)
31
    {
32
        $default = [
33 68
            'extremes' => false,
34
            'readonly' => true,
35
            'max_execution_time' => 20.0,
36
            'enable_http_compression' => 1,
37
            'https' => false,
38
        ];
39
40 68
        $this->settings = $default;
41 68
        $this->client = $client;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
42 68
    }
43
44
    /**
45
     * @param string|int $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
46
     * @return mixed
47
     */
48 55
    public function get($key)
49
    {
50 55
        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...
51
            return null;
52
        }
53 55
        return $this->settings[$key];
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
54
    }
55
56
    /**
57
     * @param string|int $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
58
     * @return bool
59
     */
60 55
    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...
61
    {
62 55
        return isset($this->settings[$key]);
63
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
64
65
66
    /**
67
     * @param string|int $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
68
     * @param mixed $value
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
69
     * @return $this
70
     */
71 68
    public function set($key, $value)
72
    {
73 68
        $this->settings[$key] = $value;
74 68
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
75
    }
76
77
    /**
78
     * @return mixed
79
     */
80 1
    public function getDatabase()
81
    {
82 1
        return $this->get('database');
83
    }
84
85
    /**
86
     * @param string $db
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
87
     * @return $this
88
     */
89 68
    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...
90
    {
91 68
        $this->set('database', $db);
92 68
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
93
    }
94
95
    /**
96
     * @return int
0 ignored issues
show
introduced by
Method \ClickHouseDB\Settings::getTimeOut() has useless @return annotation.
Loading history...
97
     */
98 46
    public function getTimeOut(): int
0 ignored issues
show
introduced by
Method \ClickHouseDB\Settings::getTimeOut() does not need documentation comment.
Loading history...
99
    {
100 46
        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...
101
    }
102
103
    /**
104
     * @return mixed|null
105
     */
106 45
    public function isEnableHttpCompression()
107
    {
108 45
        return $this->getSetting('enable_http_compression');
109
    }
110
111
    /**
112
     * @param bool|int $flag
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
113
     * @return $this
114
     */
115 68
    public function enableHttpCompression($flag)
116
    {
117 68
        $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...
118 68
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
119
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
120
121
122 1
    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...
123
    {
124 1
        $this->set('https', $flag);
125 1
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
126
    }
127
128 55
    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...
129
    {
130 55
        return $this->get('https');
131
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
132
133
134
    /**
135
     * @param int|bool $flag
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
136
     * @return $this
137
     */
138
    public function readonly($flag)
139
    {
140
        $this->set('readonly', $flag);
141
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
142
    }
143
144
    /**
145
     * @param string $session_id
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
146
     * @return $this
147
     */
148 2
    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...
149
    {
150 2
        $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...
151 2
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
152
    }
153
154
    /**
155
     * @return mixed|bool
156
     */
157 46
    public function getSessionId()
158
    {
159 46
        if (empty($this->settings['session_id'])) {
0 ignored issues
show
introduced by
Expected 1 lines after "if", found 0.
Loading history...
160 46
            return false;
161
        }
162 2
        return $this->get('session_id');
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
163
    }
164
165
    /**
166
     * @return string|bool
167
     */
168 2
    public function makeSessionId()
169
    {
170 2
        $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...
171 2
        return $this->getSessionId();
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
172
    }
173
174
    /**
175
     *
176
     * 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...
177
     *
178 2
     * @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...
179
     * @return $this
180 2
     */
181 2
    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...
182
    {
183
        $this->set('max_execution_time',$time);
184
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
185
    }
186
187 45
    /**
188
     * @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...
189 45
     */
190
    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...
191
    {
192
        return $this->settings;
193
    }
194
195
    /**
196 1
     * @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...
197
     * @return $this
198 1
     */
199 1
    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...
200
    {
201
        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...
202 1
            $this->set($key, $value);
203
        }
204
205
        return $this;
206
    }
207
208
    /**
209
     * @param int|bool $flag
210
     */
211
    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...
212
    {
213
        $this->_ReadOnlyUser = $flag;
0 ignored issues
show
Coding Style introduced by
Member variable "_ReadOnlyUser" is not in valid camel caps format
Loading history...
214
    }
215
216 45
    /**
217
     * @return bool
0 ignored issues
show
introduced by
Method \ClickHouseDB\Settings::isReadOnlyUser() has useless @return annotation.
Loading history...
218 45
     */
219
    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...
220
    {
221
        return $this->_ReadOnlyUser;
0 ignored issues
show
Coding Style introduced by
Member variable "_ReadOnlyUser" is not in valid camel caps format
Loading history...
222
    }
223
224
    /**
225 46
     * @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...
226
     * @return mixed|null
227 46
     */
228
    public function getSetting(string $name)
229
    {
230
        if (!isset($this->settings[$name])) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after NOT operator; 0 found
Loading history...
231 46
            return null;
232
        }
233
234
        return $this->get($name);
235
    }
236
}
237