Passed
Push — master ( 4c2c3a...7a13fc )
by Igor
03:32
created
src/Cluster.php 1 patch
Spacing   +39 added lines, -39 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,24 +503,24 @@  discard block
 block discarded – undo
503 503
      */
504 504
     public function getSizeTable($database_table)
505 505
     {
506
-       $list=[];
507
-       $nodes=$this->getNodesByTable($database_table);
506
+       $list = [];
507
+       $nodes = $this->getNodesByTable($database_table);
508 508
         // scan need node`s
509 509
         foreach ($nodes as $node)
510 510
         {
511 511
             if (empty($this->_table_size_cache[$node]))
512 512
             {
513
-                $this->_table_size_cache[$node]=$this->client($node)->tablesSize(true);
513
+                $this->_table_size_cache[$node] = $this->client($node)->tablesSize(true);
514 514
             }
515 515
         }
516 516
 
517
-        $sizes=[];
517
+        $sizes = [];
518 518
         foreach ($this->_table_size_cache as $node=>$rows)
519 519
         {
520 520
             foreach ($rows as $row)
521 521
             {
522
-                $sizes[$row['database'].'.'.$row['table']][$node]=$row;
523
-                @$sizes[$row['database'].'.'.$row['table']]['total']['sizebytes']+=$row['sizebytes'];
522
+                $sizes[$row['database'] . '.' . $row['table']][$node] = $row;
523
+                @$sizes[$row['database'] . '.' . $row['table']]['total']['sizebytes'] += $row['sizebytes'];
524 524
 
525 525
 
526 526
 
@@ -542,17 +542,17 @@  discard block
 block discarded – undo
542 542
      * @return array
543 543
      * @throws Exception\TransportException
544 544
      */
545
-    public function truncateTable($database_table,$timeOut=2000)
545
+    public function truncateTable($database_table, $timeOut = 2000)
546 546
     {
547
-        $out=[];
548
-        list($db,$table)=explode('.',$database_table);
549
-        $nodes=$this->getMasterNodeForTable($database_table);
547
+        $out = [];
548
+        list($db, $table) = explode('.', $database_table);
549
+        $nodes = $this->getMasterNodeForTable($database_table);
550 550
         // scan need node`s
551 551
         foreach ($nodes as $node)
552 552
         {
553
-            $def=$this->client($node)->getTimeout();
553
+            $def = $this->client($node)->getTimeout();
554 554
             $this->client($node)->database($db)->setTimeout($timeOut);
555
-            $out[$node]=$this->client($node)->truncateTable($table);
555
+            $out[$node] = $this->client($node)->truncateTable($table);
556 556
             $this->client($node)->setTimeout($def);
557 557
         }
558 558
         return $out;
@@ -567,15 +567,15 @@  discard block
 block discarded – undo
567 567
      */
568 568
     public function getMasterNodeForTable($database_table)
569 569
     {
570
-        $list=$this->getTables(true);
570
+        $list = $this->getTables(true);
571 571
 
572 572
         if (empty($list[$database_table])) return [];
573 573
 
574 574
 
575
-        $result=[];
575
+        $result = [];
576 576
         foreach ($list[$database_table] as $node=>$row)
577 577
         {
578
-            if ($row['is_leader']) $result[]=$node;
578
+            if ($row['is_leader']) $result[] = $node;
579 579
         }
580 580
         return $result;
581 581
     }
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
      */
589 589
     public function getNodesByTable($database_table)
590 590
     {
591
-        $list=$this->getTables();
591
+        $list = $this->getTables();
592 592
         if (empty($list[$database_table])) {
593 593
             throw new QueryException('Not find :' . $database_table);
594 594
         }
Please login to merge, or discard this patch.
src/Statement.php 1 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.