Completed
Push — master ( 8040a7...b5bbbe )
by Igor
22:35 queued 13:29
created
src/Cluster.php 3 patches
Braces   +29 added lines, -13 removed lines patch added patch discarded remove patch
@@ -193,7 +193,9 @@  discard block
 block discarded – undo
193 193
 //            if ($replica['total_replicas']<2) {$ok=false;$this->error[]='total_replicas : '.json_encode($replica);}
194 194
             if ($this->softCheck )
195 195
             {
196
-                if (!$ok) break;
196
+                if (!$ok) {
197
+                    break;
198
+                }
197 199
                 continue;
198 200
             }
199 201
 
@@ -209,7 +211,9 @@  discard block
 block discarded – undo
209 211
                 $ok = false;
210 212
                 $this->error[] = 'log_max_index : ' . json_encode($replica);
211 213
             }
212
-            if (!$ok) break;
214
+            if (!$ok) {
215
+                break;
216
+            }
213 217
         }
214 218
         return $ok;
215 219
     }
@@ -308,7 +312,9 @@  discard block
 block discarded – undo
308 312
             // Let's check that replication goes well
309 313
             $rIsOk = $this->isReplicasWork($result['replicas'][$node]);
310 314
             $result['replicasIsOk'][$node] = $rIsOk;
311
-            if (!$rIsOk) $replicasIsOk = false;
315
+            if (!$rIsOk) {
316
+                $replicasIsOk = false;
317
+            }
312 318
             // ---------------------------------------------------------------------------------------------------
313 319
         }
314 320
 
@@ -328,7 +334,9 @@  discard block
 block discarded – undo
328 334
             $this->error[] = 'Have bad node : ' . json_encode($this->badNodes);
329 335
             $this->replicasIsOk = false;
330 336
         }
331
-        if (!sizeof($this->error)) $this->error = false;
337
+        if (!sizeof($this->error)) {
338
+            $this->error = false;
339
+        }
332 340
         $this->resultScan = $result;
333 341
         // @todo  : We connect to everyone in the DNS list, we need to decry that the requests were returned by all the hosts to which we connected
334 342
         return $this;
@@ -376,16 +384,19 @@  discard block
 block discarded – undo
376 384
                     if (in_array($node,$nodes_check))
377 385
                     {
378 386
                         $find=$node;
379
-                    }
380
-                    else
387
+                    } else
381 388
                     {
382 389
                         // node exists on cluster, but not check
383 390
                     }
384 391
 
385 392
                 }
386
-                if ($find) break;
393
+                if ($find) {
394
+                    break;
395
+                }
396
+            }
397
+            if ($find) {
398
+                break;
387 399
             }
388
-            if ($find) break;
389 400
         }
390 401
         if (!$find){
391 402
             $find=$nodes[0];
@@ -435,7 +446,9 @@  discard block
 block discarded – undo
435 446
     public function getClusterInfoTable($cluster)
436 447
     {
437 448
         $this->connect();
438
-        if (empty($this->resultScan['cluster.list'][$cluster])) throw new QueryException('Cluster not find:' . $cluster);
449
+        if (empty($this->resultScan['cluster.list'][$cluster])) {
450
+            throw new QueryException('Cluster not find:' . $cluster);
451
+        }
439 452
         return $this->resultScan['cluster.list'][$cluster];
440 453
     }
441 454
 
@@ -474,8 +487,7 @@  discard block
 block discarded – undo
474 487
                 if ($resultDetail)
475 488
                 {
476 489
                     $list[$db_name.'.'.$table_name]=$nodes;
477
-                }
478
-                else
490
+                } else
479 491
                 {
480 492
                     $list[$db_name.'.'.$table_name]=array_keys($nodes);
481 493
                 }
@@ -557,13 +569,17 @@  discard block
 block discarded – undo
557 569
     {
558 570
         $list=$this->getTables(true);
559 571
 
560
-        if (empty($list[$database_table])) return [];
572
+        if (empty($list[$database_table])) {
573
+            return [];
574
+        }
561 575
 
562 576
 
563 577
         $result=[];
564 578
         foreach ($list[$database_table] as $node=>$row)
565 579
         {
566
-            if ($row['is_leader']) $result[]=$node;
580
+            if ($row['is_leader']) {
581
+                $result[]=$node;
582
+            }
567 583
         }
568 584
         return $result;
569 585
     }
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -503,7 +503,7 @@
 block discarded – undo
503 503
      */
504 504
     public function getSizeTable($database_table)
505 505
     {
506
-       $nodes=$this->getNodesByTable($database_table);
506
+        $nodes=$this->getNodesByTable($database_table);
507 507
         // scan need node`s
508 508
         foreach ($nodes as $node)
509 509
         {
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     /**
43 43
      * @var int|float
44 44
      */
45
-    private $scanTimeOut=10;
45
+    private $scanTimeOut = 10;
46 46
 
47 47
     /**
48 48
      * @var array
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      *
78 78
      * @var array
79 79
      */
80
-    private $_table_size_cache=[];
80
+    private $_table_size_cache = [];
81 81
 
82 82
     /**
83 83
      * Cluster constructor.
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
             // @todo : rewrite total_replicas=1 если кластер без реплики , нужно проверять какой класте и сколько в нем реплик
193 193
 //            if ($replica['total_replicas']<2) {$ok=false;$this->error[]='total_replicas : '.json_encode($replica);}
194
-            if ($this->softCheck )
194
+            if ($this->softCheck)
195 195
             {
196 196
                 if (!$ok) break;
197 197
                 continue;
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
             $statementsClusters[$node]->getRequest()->setDnsCache(0)->timeOut($this->scanTimeOut)->connectTimeOut($this->scanTimeOut);
263 263
         }
264 264
         $this->defaultClient()->executeAsync();
265
-        $tables=[];
265
+        $tables = [];
266 266
 
267 267
         foreach ($this->nodes as $node) {
268 268
 
@@ -270,16 +270,16 @@  discard block
 block discarded – undo
270 270
             try {
271 271
                 $r = $statementsReplicas[$node]->rows();
272 272
                 foreach ($r as $row) {
273
-                    $tables[$row['database']][$row['table']][$node] =$row;
273
+                    $tables[$row['database']][$row['table']][$node] = $row;
274 274
                 }
275 275
                 $result['replicas'][$node] = $r;
276
-            } catch (\Exception $E) {
276
+            }catch (\Exception $E) {
277 277
                 $result['replicas'][$node] = false;
278 278
                 $badNodes[$node] = $E->getMessage();
279 279
                 $this->error[] = 'statementsReplicas:' . $E->getMessage();
280 280
             }
281 281
             // ---------------------------------------------------------------------------------------------------
282
-            $hosts=[];
282
+            $hosts = [];
283 283
 
284 284
             try {
285 285
                 $c = $statementsClusters[$node]->rows();
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
                         ];
296 296
                 }
297 297
 
298
-            } catch (\Exception $E) {
298
+            }catch (\Exception $E) {
299 299
                 $result['clusters'][$node] = false;
300 300
 
301 301
                 $this->error[] = 'clusters:' . $E->getMessage();
@@ -363,22 +363,22 @@  discard block
 block discarded – undo
363 363
      * @return Client
364 364
      * @throws Exception\TransportException
365 365
      */
366
-    public function clientLike($cluster,$ip_addr_like)
366
+    public function clientLike($cluster, $ip_addr_like)
367 367
     {
368
-        $nodes_check=$this->nodes;
369
-        $nodes=$this->getClusterNodes($cluster);
370
-        $list_ips_need=explode(';',$ip_addr_like);
371
-        $find=false;
372
-        foreach($list_ips_need as $like)
368
+        $nodes_check = $this->nodes;
369
+        $nodes = $this->getClusterNodes($cluster);
370
+        $list_ips_need = explode(';', $ip_addr_like);
371
+        $find = false;
372
+        foreach ($list_ips_need as $like)
373 373
         {
374 374
             foreach ($nodes as $node)
375 375
             {
376 376
 
377
-                if (stripos($node,$like)!==false)
377
+                if (stripos($node, $like) !== false)
378 378
                 {
379
-                    if (in_array($node,$nodes_check))
379
+                    if (in_array($node, $nodes_check))
380 380
                     {
381
-                        $find=$node;
381
+                        $find = $node;
382 382
                     }
383 383
                     else
384 384
                     {
@@ -390,8 +390,8 @@  discard block
 block discarded – undo
390 390
             }
391 391
             if ($find) break;
392 392
         }
393
-        if (!$find){
394
-            $find=$nodes[0];
393
+        if (!$find) {
394
+            $find = $nodes[0];
395 395
         }
396 396
         return $this->client($find);
397 397
     }
@@ -471,10 +471,10 @@  discard block
 block discarded – undo
471 471
      * @return array
472 472
      * @throws Exception\TransportException
473 473
      */
474
-    public function getTables($resultDetail=false)
474
+    public function getTables($resultDetail = false)
475 475
     {
476 476
         $this->connect();
477
-        $list=[];
477
+        $list = [];
478 478
         foreach ($this->tables as $db_name=>$tables)
479 479
         {
480 480
             foreach ($tables as $table_name=>$nodes)
@@ -482,11 +482,11 @@  discard block
 block discarded – undo
482 482
 
483 483
                 if ($resultDetail)
484 484
                 {
485
-                    $list[$db_name.'.'.$table_name]=$nodes;
485
+                    $list[$db_name . '.' . $table_name] = $nodes;
486 486
                 }
487 487
                 else
488 488
                 {
489
-                    $list[$db_name.'.'.$table_name]=array_keys($nodes);
489
+                    $list[$db_name . '.' . $table_name] = array_keys($nodes);
490 490
                 }
491 491
             }
492 492
         }
@@ -503,23 +503,23 @@  discard block
 block discarded – undo
503 503
      */
504 504
     public function getSizeTable($database_table)
505 505
     {
506
-       $nodes=$this->getNodesByTable($database_table);
506
+       $nodes = $this->getNodesByTable($database_table);
507 507
         // scan need node`s
508 508
         foreach ($nodes as $node)
509 509
         {
510 510
             if (empty($this->_table_size_cache[$node]))
511 511
             {
512
-                $this->_table_size_cache[$node]=$this->client($node)->tablesSize(true);
512
+                $this->_table_size_cache[$node] = $this->client($node)->tablesSize(true);
513 513
             }
514 514
         }
515 515
 
516
-        $sizes=[];
516
+        $sizes = [];
517 517
         foreach ($this->_table_size_cache as $node=>$rows)
518 518
         {
519 519
             foreach ($rows as $row)
520 520
             {
521
-                $sizes[$row['database'].'.'.$row['table']][$node]=$row;
522
-                @$sizes[$row['database'].'.'.$row['table']]['total']['sizebytes']+=$row['sizebytes'];
521
+                $sizes[$row['database'] . '.' . $row['table']][$node] = $row;
522
+                @$sizes[$row['database'] . '.' . $row['table']]['total']['sizebytes'] += $row['sizebytes'];
523 523
 
524 524
 
525 525
 
@@ -541,17 +541,17 @@  discard block
 block discarded – undo
541 541
      * @return array
542 542
      * @throws Exception\TransportException
543 543
      */
544
-    public function truncateTable($database_table,$timeOut=2000)
544
+    public function truncateTable($database_table, $timeOut = 2000)
545 545
     {
546
-        $out=[];
547
-        list($db,$table)=explode('.',$database_table);
548
-        $nodes=$this->getMasterNodeForTable($database_table);
546
+        $out = [];
547
+        list($db, $table) = explode('.', $database_table);
548
+        $nodes = $this->getMasterNodeForTable($database_table);
549 549
         // scan need node`s
550 550
         foreach ($nodes as $node)
551 551
         {
552
-            $def=$this->client($node)->getTimeout();
552
+            $def = $this->client($node)->getTimeout();
553 553
             $this->client($node)->database($db)->setTimeout($timeOut);
554
-            $out[$node]=$this->client($node)->truncateTable($table);
554
+            $out[$node] = $this->client($node)->truncateTable($table);
555 555
             $this->client($node)->setTimeout($def);
556 556
         }
557 557
         return $out;
@@ -566,15 +566,15 @@  discard block
 block discarded – undo
566 566
      */
567 567
     public function getMasterNodeForTable($database_table)
568 568
     {
569
-        $list=$this->getTables(true);
569
+        $list = $this->getTables(true);
570 570
 
571 571
         if (empty($list[$database_table])) return [];
572 572
 
573 573
 
574
-        $result=[];
574
+        $result = [];
575 575
         foreach ($list[$database_table] as $node=>$row)
576 576
         {
577
-            if ($row['is_leader']) $result[]=$node;
577
+            if ($row['is_leader']) $result[] = $node;
578 578
         }
579 579
         return $result;
580 580
     }
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
      */
588 588
     public function getNodesByTable($database_table)
589 589
     {
590
-        $list=$this->getTables();
590
+        $list = $this->getTables();
591 591
         if (empty($list[$database_table])) {
592 592
             throw new QueryException('Not find :' . $database_table);
593 593
         }
Please login to merge, or discard this patch.
src/Settings.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -16,12 +16,12 @@  discard block
 block discarded – undo
16 16
      */
17 17
     private $settings = [];
18 18
 
19
-    private $_ReadOnlyUser=false;
19
+    private $_ReadOnlyUser = false;
20 20
 
21 21
     /**
22 22
      * @var bool
23 23
      */
24
-    private $_isHttps=false;
24
+    private $_isHttps = false;
25 25
 
26 26
     /**
27 27
      * Settings constructor.
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
     }
117 117
 
118 118
 
119
-    public function https($flag=true)
119
+    public function https($flag = true)
120 120
     {
121 121
         $this->set('https', $flag);
122 122
         return $this;
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
      */
202 202
     public function setReadOnlyUser($flag)
203 203
     {
204
-        $this->_ReadOnlyUser=$flag;
204
+        $this->_ReadOnlyUser = $flag;
205 205
     }
206 206
 
207 207
     /**
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -47,7 +47,9 @@  discard block
 block discarded – undo
47 47
      */
48 48
     public function get($key)
49 49
     {
50
-        if (!$this->is($key)) return null;
50
+        if (!$this->is($key)) {
51
+            return null;
52
+        }
51 53
         return $this->settings[$key];
52 54
     }
53 55
 
@@ -153,7 +155,9 @@  discard block
 block discarded – undo
153 155
      */
154 156
     public function getSessionId()
155 157
     {
156
-        if (empty($this->settings['session_id'])) return false;
158
+        if (empty($this->settings['session_id'])) {
159
+            return false;
160
+        }
157 161
         return $this->get('session_id');
158 162
     }
159 163
 
Please login to merge, or discard this patch.
src/Query/Query.php 2 patches
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -49,7 +49,9 @@  discard block
 block discarded – undo
49 49
     private function applyFormatQuery()
50 50
     {
51 51
         // FORMAT\s(\w)*$
52
-        if (null === $this->format) return false;
52
+        if (null === $this->format) {
53
+            return false;
54
+        }
53 55
         $supportFormats=
54 56
             "FORMAT\\s+TSV|FORMAT\\s+TSVRaw|FORMAT\\s+TSVWithNames|FORMAT\\s+TSVWithNamesAndTypes|FORMAT\\s+Vertical|FORMAT\\s+JSONCompact|FORMAT\\s+JSONEachRow|FORMAT\\s+TSKV|FORMAT\\s+TabSeparatedWithNames|FORMAT\\s+TabSeparatedWithNamesAndTypes|FORMAT\\s+TabSeparatedRaw|FORMAT\\s+BlockTabSeparated|FORMAT\\s+CSVWithNames|FORMAT\\s+CSV|FORMAT\\s+JSON|FORMAT\\s+TabSeparated";
55 57
 
@@ -63,8 +65,7 @@  discard block
 block discarded – undo
63 65
                 $this->format=trim(str_ireplace('format','',$matches[0][0]));
64 66
 
65 67
             }
66
-        }
67
-        else {
68
+        } else {
68 69
             $this->sql = $this->sql . ' FORMAT ' . $this->format;
69 70
         }
70 71
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -20,21 +20,21 @@  discard block
 block discarded – undo
20 20
     /**
21 21
      * @var array
22 22
      */
23
-    private $degenerations=[];
23
+    private $degenerations = [];
24 24
 
25 25
     /**
26 26
      * Query constructor.
27 27
      * @param string $sql
28 28
      * @param array $degenerations
29 29
      */
30
-    public function __construct($sql,$degenerations=[])
30
+    public function __construct($sql, $degenerations = [])
31 31
     {
32 32
         if (!trim($sql))
33 33
         {
34 34
             throw new QueryException('Empty Query');
35 35
         }
36 36
         $this->sql = $sql;
37
-        $this->degenerations=$degenerations;
37
+        $this->degenerations = $degenerations;
38 38
     }
39 39
 
40 40
     /**
@@ -50,17 +50,17 @@  discard block
 block discarded – undo
50 50
     {
51 51
         // FORMAT\s(\w)*$
52 52
         if (null === $this->format) return false;
53
-        $supportFormats=
53
+        $supportFormats =
54 54
             "FORMAT\\s+TSV|FORMAT\\s+TSVRaw|FORMAT\\s+TSVWithNames|FORMAT\\s+TSVWithNamesAndTypes|FORMAT\\s+Vertical|FORMAT\\s+JSONCompact|FORMAT\\s+JSONEachRow|FORMAT\\s+TSKV|FORMAT\\s+TabSeparatedWithNames|FORMAT\\s+TabSeparatedWithNamesAndTypes|FORMAT\\s+TabSeparatedRaw|FORMAT\\s+BlockTabSeparated|FORMAT\\s+CSVWithNames|FORMAT\\s+CSV|FORMAT\\s+JSON|FORMAT\\s+TabSeparated";
55 55
 
56
-        $matches=[];
57
-        if (preg_match_all('%('.$supportFormats.')%ius',$this->sql,$matches)){
56
+        $matches = [];
57
+        if (preg_match_all('%(' . $supportFormats . ')%ius', $this->sql, $matches)) {
58 58
 
59 59
             // skip add "format json"
60 60
             if (isset($matches[0]))
61 61
             {
62 62
 
63
-                $this->format=trim(str_ireplace('format','',$matches[0][0]));
63
+                $this->format = trim(str_ireplace('format', '', $matches[0][0]));
64 64
 
65 65
             }
66 66
         }
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             foreach ($this->degenerations as $degeneration)
96 96
             {
97 97
                 if ($degeneration instanceof Degeneration) {
98
-                    $this->sql=$degeneration->process($this->sql);
98
+                    $this->sql = $degeneration->process($this->sql);
99 99
                 }
100 100
             }
101 101
         }
Please login to merge, or discard this patch.
src/Statement.php 2 patches
Braces   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -167,13 +167,11 @@  discard block
 block discarded – undo
167 167
 
168 168
             if ($parse) {
169 169
                 throw new DatabaseException($parse['message'] . "\nIN:" . $this->sql(), $parse['code']);
170
-            }
171
-            else {
170
+            } else {
172 171
                 $code = $this->response()->http_code();
173 172
                 $message = "HttpCode:" . $this->response()->http_code() . " ; ".$this->response()->error()." ;" . $body;
174 173
             }
175
-        }
176
-        else {
174
+        } else {
177 175
             $code = $error_no;
178 176
             $message = $this->response()->error();
179 177
         }
@@ -349,8 +347,12 @@  discard block
 block discarded – undo
349 347
         $this->init();
350 348
         if ($key)
351 349
         {
352
-            if (!is_array($this->statistics)) return null;
353
-            if (!isset($this->statistics[$key])) return null;
350
+            if (!is_array($this->statistics)) {
351
+                return null;
352
+            }
353
+            if (!isset($this->statistics[$key])) {
354
+                return null;
355
+            }
354 356
             return $this->statistics[$key];
355 357
         }
356 358
         return $this->statistics;
@@ -394,8 +396,7 @@  discard block
 block discarded – undo
394 396
             if ($key) {
395 397
                 if (isset($this->array_data[0][$key])) {
396 398
                     return $this->array_data[0][$key];
397
-                }
398
-                else {
399
+                } else {
399 400
                     return null;
400 401
                 }
401 402
             }
@@ -489,16 +490,14 @@  discard block
 block discarded – undo
489 490
     {
490 491
         if (is_array($path)) {
491 492
             $keys = $path;
492
-        }
493
-        else {
493
+        } else {
494 494
             $args = func_get_args();
495 495
             array_shift($args);
496 496
 
497 497
             if (sizeof($args) < 2) {
498 498
                 $separator = '.';
499 499
                 $keys = explode($separator, $path);
500
-            }
501
-            else {
500
+            } else {
502 501
                 $keys = $args;
503 502
             }
504 503
         }
@@ -510,14 +509,15 @@  discard block
 block discarded – undo
510 509
 
511 510
             if (isset($arr[$key])) {
512 511
                 $val = $arr[$key];
513
-            }
514
-            else {
512
+            } else {
515 513
                 $val = $key;
516 514
             }
517 515
 
518 516
             $tree = array($val => $tree);
519 517
         }
520
-        if (!is_array($tree)) return [];
518
+        if (!is_array($tree)) {
519
+            return [];
520
+        }
521 521
         return $tree;
522 522
     }
523 523
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
     /**
84 84
      * @var array|null
85 85
      */
86
-    private $statistics=null;
86
+    private $statistics = null;
87 87
 
88 88
 
89 89
     public function __construct(CurlerRequest $request)
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 
161 161
         $body = $this->response()->body();
162 162
         $error_no = $this->response()->error_no();
163
-        $error=$this->response()->error();
163
+        $error = $this->response()->error();
164 164
 
165 165
         if (!$error_no && !$error) {
166 166
             $parse = $this->parseErrorClickHouse($body);
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
             }
171 171
             else {
172 172
                 $code = $this->response()->http_code();
173
-                $message = "HttpCode:" . $this->response()->http_code() . " ; ".$this->response()->error()." ;" . $body;
173
+                $message = "HttpCode:" . $this->response()->http_code() . " ; " . $this->response()->error() . " ;" . $body;
174 174
             }
175 175
         }
176 176
         else {
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
             return false;
228 228
         }
229 229
 
230
-        foreach (['meta', 'data', 'totals', 'extremes', 'rows', 'rows_before_limit_at_least','statistics'] as $key) {
230
+        foreach (['meta', 'data', 'totals', 'extremes', 'rows', 'rows_before_limit_at_least', 'statistics'] as $key) {
231 231
             if (isset($this->_rawData[$key])) {
232 232
                 $this->{$key} = $this->_rawData[$key];
233 233
             }
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      * @return array|mixed|null
345 345
      * @throws Exception\TransportException
346 346
      */
347
-    public function statistics($key=false)
347
+    public function statistics($key = false)
348 348
     {
349 349
         $this->init();
350 350
         if ($key)
Please login to merge, or discard this patch.