Passed
Push — master ( 4e99ce...4c2c3a )
by Igor
05:31
created
src/Transport/CurlerRequest.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     /**
48 48
      * @var CurlerResponse
49 49
      */
50
-    private $resp=null;
50
+    private $resp = null;
51 51
 
52 52
     /**
53 53
      * @var bool
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     /**
78 78
      * @var callable
79 79
      */
80
-    private $callback_function=null;
80
+    private $callback_function = null;
81 81
 
82 82
     /**
83 83
      * @var bool
@@ -109,13 +109,13 @@  discard block
 block discarded – undo
109 109
             CURLOPT_SSL_VERIFYHOST => 0,
110 110
             CURLOPT_SSL_VERIFYPEER => false,
111 111
             CURLOPT_TIMEOUT => 10,
112
-            CURLOPT_CONNECTTIMEOUT => 5,    // Количество секунд ожидания при попытке соединения
112
+            CURLOPT_CONNECTTIMEOUT => 5, // Количество секунд ожидания при попытке соединения
113 113
             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
114 114
             CURLOPT_MAXREDIRS => 10,
115 115
             CURLOPT_HEADER => TRUE,
116 116
             CURLOPT_FOLLOWLOCATION => TRUE,
117
-            CURLOPT_AUTOREFERER => 1,       // при редиректе подставлять в «Referer:» значение из «Location:»
118
-            CURLOPT_BINARYTRANSFER => 1,    // передавать в binary-safe
117
+            CURLOPT_AUTOREFERER => 1, // при редиректе подставлять в «Referer:» значение из «Location:»
118
+            CURLOPT_BINARYTRANSFER => 1, // передавать в binary-safe
119 119
             CURLOPT_RETURNTRANSFER => TRUE,
120 120
             CURLOPT_USERAGENT => 'smi2/PHPClickHouse/client',
121 121
         );
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
      */
239 239
     public function setReadFunction($callback)
240 240
     {
241
-        $this->options[CURLOPT_READFUNCTION]=$callback;
241
+        $this->options[CURLOPT_READFUNCTION] = $callback;
242 242
     }
243 243
 
244 244
     /**
@@ -363,9 +363,9 @@  discard block
 block discarded – undo
363 363
      */
364 364
     public function getHeaders()
365 365
     {
366
-        $head=[];
366
+        $head = [];
367 367
         foreach ($this->headers as $key=>$value)
368
-            $head[]= sprintf("%s: %s", $key, $value);
368
+            $head[] = sprintf("%s: %s", $key, $value);
369 369
         return $head;
370 370
     }
371 371
 
@@ -640,8 +640,8 @@  discard block
 block discarded – undo
640 640
             throw new \Exception('setFunctionProgress not is_callable');
641 641
         }
642 642
 
643
-        $this->option(CURLOPT_NOPROGRESS,false);
644
-        $this->option(CURLOPT_PROGRESSFUNCTION,$callback); // version 5.5.0
643
+        $this->option(CURLOPT_NOPROGRESS, false);
644
+        $this->option(CURLOPT_PROGRESSFUNCTION, $callback); // version 5.5.0
645 645
     }
646 646
 
647 647
 
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
         }
705 705
 
706 706
         if ($this->options[CURLOPT_VERBOSE]) {
707
-            echo "\n-----------BODY REQUEST----------\n".$curl_opt[CURLOPT_POSTFIELDS]."\n------END--------\n";
707
+            echo "\n-----------BODY REQUEST----------\n" . $curl_opt[CURLOPT_POSTFIELDS] . "\n------END--------\n";
708 708
         }
709 709
         curl_setopt_array($this->handle, $curl_opt);
710 710
         return true;
Please login to merge, or discard this patch.
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.