Passed
Push — master ( 4c2c3a...7a13fc )
by Igor
03:32
created
src/Settings.php 1 patch
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.
example/cluster/cluster_06_truncate_table.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,27 +13,27 @@
 block discarded – undo
13 13
 $cl->setSoftCheck(true);
14 14
 if (!$cl->isReplicasIsOk())
15 15
 {
16
-    throw new Exception('Replica state is bad , error='.$cl->getError());
16
+    throw new Exception('Replica state is bad , error=' . $cl->getError());
17 17
 }
18 18
 
19 19
 
20
-$tables=$cl->getTables();
20
+$tables = $cl->getTables();
21 21
 
22 22
 foreach ($tables as $dbtable=>$tmp)
23 23
 {
24 24
     echo ">>> $dbtable :";
25 25
 
26
-    $size=$cl->getSizeTable($dbtable);
26
+    $size = $cl->getSizeTable($dbtable);
27 27
 
28 28
 
29
-    echo "\t".\ClickHouseDB\Example\Helper::humanFileSize($size)."\n";
29
+    echo "\t" . \ClickHouseDB\Example\Helper::humanFileSize($size) . "\n";
30 30
 
31 31
 }
32 32
 
33 33
 
34
-$table_for_truncate='target.events_sharded';
34
+$table_for_truncate = 'target.events_sharded';
35 35
 
36
-$result=$cl->truncateTable($table_for_truncate);
36
+$result = $cl->truncateTable($table_for_truncate);
37 37
 
38 38
 echo "Result:truncate table\n";
39 39
 print_r($result);
Please login to merge, or discard this patch.
example/exam17_sample_data_cityHash64.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -8,20 +8,20 @@  discard block
 block discarded – undo
8 8
 
9 9
 
10 10
 $db = new ClickHouseDB\Client($config);
11
-$_flag_create_table=false;
11
+$_flag_create_table = false;
12 12
 
13
-$size=$db->tableSize('summing_url_views_cityHash64_site_id');
14
-echo "Site table summing_url_views_cityHash64_site_id : ".(isset($size['size'])?$size['size']:'false')."\n";
13
+$size = $db->tableSize('summing_url_views_cityHash64_site_id');
14
+echo "Site table summing_url_views_cityHash64_site_id : " . (isset($size['size']) ? $size['size'] : 'false') . "\n";
15 15
 
16 16
 
17
-if (!isset($size['size'])) $_flag_create_table=true;
17
+if (!isset($size['size'])) $_flag_create_table = true;
18 18
 
19 19
 
20 20
 if ($_flag_create_table) {
21 21
 
22 22
 
23 23
     $db->write("DROP TABLE IF EXISTS summing_url_views_cityHash64_site_id");
24
-    $re=$db->write('
24
+    $re = $db->write('
25 25
                 CREATE TABLE IF NOT EXISTS summing_url_views_cityHash64_site_id (
26 26
                     event_date Date DEFAULT toDate(event_time),
27 27
                     event_time DateTime,
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
     $c = 0;
49 49
     foreach ($file_data_names as $file_name) {
50 50
         $c++;
51
-        $shift_days=( -1* $c*3);
52
-        \ClickHouseDB\Example\Helper::makeSomeDataFileBig($file_name, 23 * $c,$shift_days);
51
+        $shift_days = ( -1 * $c * 3);
52
+        \ClickHouseDB\Example\Helper::makeSomeDataFileBig($file_name, 23 * $c, $shift_days);
53 53
     }
54 54
 
55 55
     echo "----------------------------------------------------------------------------------------------------\n";
@@ -75,56 +75,56 @@  discard block
 block discarded – undo
75 75
 }
76 76
 echo "------------------------------- COMPARE event_date ---------------------------------------------------------------------\n";
77 77
 
78
-$rows=($db->select('select event_date,sum(views) as v from summing_url_views_cityHash64_site_id GROUP BY event_date ORDER BY event_date')->rowsAsTree('event_date'));
78
+$rows = ($db->select('select event_date,sum(views) as v from summing_url_views_cityHash64_site_id GROUP BY event_date ORDER BY event_date')->rowsAsTree('event_date'));
79 79
 
80
-$samp=($db->select('select event_date,(sum(views)*10) as v from summing_url_views_cityHash64_site_id SAMPLE 0.1 GROUP BY event_date ORDER BY event_date ')->rowsAsTree('event_date'));
80
+$samp = ($db->select('select event_date,(sum(views)*10) as v from summing_url_views_cityHash64_site_id SAMPLE 0.1 GROUP BY event_date ORDER BY event_date ')->rowsAsTree('event_date'));
81 81
 
82 82
 
83 83
 foreach ($rows as $event_date=>$data)
84 84
 {
85
-    echo $event_date."\t".$data['v']."\t".@$samp[$event_date]['v']."\n";
85
+    echo $event_date . "\t" . $data['v'] . "\t" . @$samp[$event_date]['v'] . "\n";
86 86
 }
87 87
 
88 88
 
89
-$rows=($db->select('select site_id,sum(views) as v from summing_url_views_cityHash64_site_id GROUP BY site_id ORDER BY site_id')->rowsAsTree('site_id'));
89
+$rows = ($db->select('select site_id,sum(views) as v from summing_url_views_cityHash64_site_id GROUP BY site_id ORDER BY site_id')->rowsAsTree('site_id'));
90 90
 
91
-$samp=($db->select('select site_id,(sum(views)) as v from summing_url_views_cityHash64_site_id SAMPLE 0.5 GROUP BY site_id ORDER BY site_id ')->rowsAsTree('site_id'));
91
+$samp = ($db->select('select site_id,(sum(views)) as v from summing_url_views_cityHash64_site_id SAMPLE 0.5 GROUP BY site_id ORDER BY site_id ')->rowsAsTree('site_id'));
92 92
 
93 93
 
94 94
 foreach ($rows as $event_date=>$data)
95 95
 {
96
-    echo $event_date."\t".$data['v']."\t".intval(@$samp[$event_date]['v'])."\n";
96
+    echo $event_date . "\t" . $data['v'] . "\t" . intval(@$samp[$event_date]['v']) . "\n";
97 97
 }
98 98
 
99 99
 
100 100
 
101
-for($f=1;$f<=9;$f++)
101
+for ($f = 1; $f <= 9; $f++)
102 102
 {
103
-    $SAMPLE=$f/10;
103
+    $SAMPLE = $f / 10;
104 104
 
105
-    $CQL='select site_id,(sum(views)) as v from summing_url_views_cityHash64_site_id SAMPLE '.$SAMPLE.' WHERE site_id=34 GROUP BY site_id ORDER BY site_id ';
105
+    $CQL = 'select site_id,(sum(views)) as v from summing_url_views_cityHash64_site_id SAMPLE ' . $SAMPLE . ' WHERE site_id=34 GROUP BY site_id ORDER BY site_id ';
106 106
 
107
-    echo $CQL."\n";
108
-    $rows=($db->select('select site_id,sum(views) as v from summing_url_views_cityHash64_site_id WHERE site_id=34 GROUP BY site_id ORDER BY site_id')->rowsAsTree('site_id'));
109
-    $samp=($db->select($CQL)->rowsAsTree('site_id'));
107
+    echo $CQL . "\n";
108
+    $rows = ($db->select('select site_id,sum(views) as v from summing_url_views_cityHash64_site_id WHERE site_id=34 GROUP BY site_id ORDER BY site_id')->rowsAsTree('site_id'));
109
+    $samp = ($db->select($CQL)->rowsAsTree('site_id'));
110 110
     foreach ($rows as $id=>$data)
111 111
     {
112
-            $s=$samp[$id]['v'];
113
-            $v=$data['v'];
112
+            $s = $samp[$id]['v'];
113
+            $v = $data['v'];
114 114
 
115 115
 
116
-            $percent=round( (100*$s) /$v   ,2);
116
+            $percent = round((100 * $s) / $v, 2);
117 117
 
118
-            $kof=(100/$percent);
119
-            $norma_views=$s*(100/$percent);
118
+            $kof = (100 / $percent);
119
+            $norma_views = $s * (100 / $percent);
120 120
 
121 121
 
122 122
 
123
-            echo "Сумма показов без SAMPLE  =  " .$v."\n";
124
-            echo "Сумма показов c   SAMPLE  =  " .$s."\n";
125
-            echo "Процент                   =  " .$percent."\n";
126
-            echo "На что домжнож.семлир.данн=  " .$kof."\n";
127
-            echo "Сумма показов расчитанное =  " .$norma_views."\n";
123
+            echo "Сумма показов без SAMPLE  =  " . $v . "\n";
124
+            echo "Сумма показов c   SAMPLE  =  " . $s . "\n";
125
+            echo "Процент                   =  " . $percent . "\n";
126
+            echo "На что домжнож.семлир.данн=  " . $kof . "\n";
127
+            echo "Сумма показов расчитанное =  " . $norma_views . "\n";
128 128
 
129 129
 /// >> 1/(0.8) = для SAMPLE 0.8
130 130
 /// >> 1/(0.5) = для SAMPLE 0.5
Please login to merge, or discard this patch.
example/exam17_sample_data_inthash.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -8,26 +8,26 @@  discard block
 block discarded – undo
8 8
 
9 9
 
10 10
 $db = new ClickHouseDB\Client($config);
11
-$_flag_create_table=false;
11
+$_flag_create_table = false;
12 12
 
13 13
 
14 14
 $db->write("DROP TABLE IF EXISTS summing_url_views_intHash32_site_id");
15 15
 
16 16
 
17 17
 
18
-$size=$db->tableSize('summing_url_views_intHash32_site_id');
19
-echo "Site table summing_url_views_intHash32_site_id : ".(isset($size['size'])?$size['size']:'false')."\n";
18
+$size = $db->tableSize('summing_url_views_intHash32_site_id');
19
+echo "Site table summing_url_views_intHash32_site_id : " . (isset($size['size']) ? $size['size'] : 'false') . "\n";
20 20
 
21 21
 
22 22
 
23
-if (!isset($size['size'])) $_flag_create_table=true;
23
+if (!isset($size['size'])) $_flag_create_table = true;
24 24
 
25 25
 
26 26
 if ($_flag_create_table) {
27 27
 
28 28
 
29 29
     $db->write("DROP TABLE IF EXISTS summing_url_views_intHash32_site_id");
30
-    $re=$db->write('
30
+    $re = $db->write('
31 31
                 CREATE TABLE IF NOT EXISTS summing_url_views_intHash32_site_id (
32 32
                     event_date Date DEFAULT toDate(event_time),
33 33
                     event_time DateTime,
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
     $c = 0;
55 55
     foreach ($file_data_names as $file_name) {
56 56
         $c++;
57
-        $shift_days=( -1* $c*3);
58
-        \ClickHouseDB\Example\Helper::makeSomeDataFileBig($file_name, 4 * $c,$shift_days);
57
+        $shift_days = ( -1 * $c * 3);
58
+        \ClickHouseDB\Example\Helper::makeSomeDataFileBig($file_name, 4 * $c, $shift_days);
59 59
     }
60 60
 
61 61
     echo "----------------------------------------------------------------------------------------------------\n";
@@ -81,25 +81,25 @@  discard block
 block discarded – undo
81 81
 }
82 82
 echo "------------------------------- COMPARE event_date ---------------------------------------------------------------------\n";
83 83
 
84
-$rows=($db->select('select event_date,sum(views) as v from summing_url_views_intHash32_site_id GROUP BY event_date ORDER BY event_date')->rowsAsTree('event_date'));
84
+$rows = ($db->select('select event_date,sum(views) as v from summing_url_views_intHash32_site_id GROUP BY event_date ORDER BY event_date')->rowsAsTree('event_date'));
85 85
 
86
-$samp=($db->select('select event_date,sum(views) as v from summing_url_views_intHash32_site_id SAMPLE 0.5 GROUP BY event_date ORDER BY event_date ')->rowsAsTree('event_date'));
86
+$samp = ($db->select('select event_date,sum(views) as v from summing_url_views_intHash32_site_id SAMPLE 0.5 GROUP BY event_date ORDER BY event_date ')->rowsAsTree('event_date'));
87 87
 
88 88
 
89 89
 foreach ($rows as $event_date=>$data)
90 90
 {
91
-    echo $event_date."\t".$data['v']."\t".(@$samp[$event_date]['v']*(1/0.5))."\n";
91
+    echo $event_date . "\t" . $data['v'] . "\t" . (@$samp[$event_date]['v'] * (1 / 0.5)) . "\n";
92 92
 }
93 93
 
94 94
 
95
-$rows=($db->select('select site_id,sum(views) as v from summing_url_views_intHash32_site_id GROUP BY site_id ORDER BY site_id')->rowsAsTree('site_id'));
95
+$rows = ($db->select('select site_id,sum(views) as v from summing_url_views_intHash32_site_id GROUP BY site_id ORDER BY site_id')->rowsAsTree('site_id'));
96 96
 
97
-$samp=($db->select('select site_id,(sum(views)) as v from summing_url_views_intHash32_site_id SAMPLE 0.5 GROUP BY site_id ORDER BY site_id ')->rowsAsTree('site_id'));
97
+$samp = ($db->select('select site_id,(sum(views)) as v from summing_url_views_intHash32_site_id SAMPLE 0.5 GROUP BY site_id ORDER BY site_id ')->rowsAsTree('site_id'));
98 98
 
99 99
 
100 100
 foreach ($rows as $event_date=>$data)
101 101
 {
102
-    echo $event_date."\t".$data['v']."\t".intval(@$samp[$event_date]['v'])."\n";
102
+    echo $event_date . "\t" . $data['v'] . "\t" . intval(@$samp[$event_date]['v']) . "\n";
103 103
 }
104 104
 /*
105 105
 
Please login to merge, or discard this patch.
example/Helper.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@
 block discarded – undo
7 7
     public static function init()
8 8
     {
9 9
         date_default_timezone_set('Europe/Moscow');
10
-        error_reporting( E_ALL );
11
-        ini_set('display_errors',1);
10
+        error_reporting(E_ALL);
11
+        ini_set('display_errors', 1);
12 12
     }
13 13
 
14 14
         /**
Please login to merge, or discard this patch.
src/Client.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
     /**
40 40
      * @var bool
41 41
      */
42
-    private $_connect_user_readonly=false;
42
+    private $_connect_user_readonly = false;
43 43
     /**
44 44
      * @var array
45 45
      */
46
-    private $_support_format=['TabSeparated','TabSeparatedWithNames','CSV','CSVWithNames','JSONEachRow'];
46
+    private $_support_format = ['TabSeparated', 'TabSeparatedWithNames', 'CSV', 'CSVWithNames', 'JSONEachRow'];
47 47
 
48 48
     /**
49 49
      * Client constructor.
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public function setReadOnlyUser($flag)
122 122
     {
123
-        $this->_connect_user_readonly=$flag;
123
+        $this->_connect_user_readonly = $flag;
124 124
         $this->settings()->setReadOnlyUser($this->_connect_user_readonly);
125 125
     }
126 126
     /**
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
 
164 164
         if (is_array($host))
165 165
         {
166
-            $host=array_rand(array_flip($host));
166
+            $host = array_rand(array_flip($host));
167 167
         }
168 168
 
169
-        $this->_connect_host=$host;
169
+        $this->_connect_host = $host;
170 170
         $this->transport()->setHost($host);
171 171
     }
172 172
 
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
     /**
290 290
      * @return $this
291 291
      */
292
-    public function useSession($useSessionId=false)
292
+    public function useSession($useSessionId = false)
293 293
     {
294 294
         if (!$this->settings()->getSessionId())
295 295
         {
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
      */
347 347
     public function enableLogQueries($flag = true)
348 348
     {
349
-        $this->settings()->set('log_queries',intval($flag));
349
+        $this->settings()->set('log_queries', intval($flag));
350 350
         return $this;
351 351
     }
352 352
 
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
      * @param bool $flag
369 369
      * @return $this
370 370
      */
371
-    public function https($flag=true)
371
+    public function https($flag = true)
372 372
     {
373 373
         $this->settings()->https($flag);
374 374
         return $this;
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
      */
383 383
     public function enableExtremes($flag = true)
384 384
     {
385
-        $this->settings()->set('extremes',intval($flag));
385
+        $this->settings()->set('extremes', intval($flag));
386 386
         return $this;
387 387
     }
388 388
 
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
      * @throws Exception\TransportException
398 398
      * @throws \Exception
399 399
      */
400
-    public function select($sql, $bindings = [], $whereInFile = null, $writeToFile=null)
400
+    public function select($sql, $bindings = [], $whereInFile = null, $writeToFile = null)
401 401
     {
402
-        return $this->transport()->select($sql, $bindings, $whereInFile,$writeToFile);
402
+        return $this->transport()->select($sql, $bindings, $whereInFile, $writeToFile);
403 403
     }
404 404
 
405 405
     /**
@@ -446,9 +446,9 @@  discard block
 block discarded – undo
446 446
      * @throws Exception\TransportException
447 447
      * @throws \Exception
448 448
      */
449
-    public function selectAsync($sql, $bindings = [], $whereInFile = null,$writeToFile=null)
449
+    public function selectAsync($sql, $bindings = [], $whereInFile = null, $writeToFile = null)
450 450
     {
451
-        return $this->transport()->selectAsync($sql, $bindings, $whereInFile,$writeToFile);
451
+        return $this->transport()->selectAsync($sql, $bindings, $whereInFile, $writeToFile);
452 452
     }
453 453
 
454 454
     /**
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
      */
486 486
     public function showCreateTable($table)
487 487
     {
488
-        return ($this->select('SHOW CREATE TABLE '.$table)->fetchOne('statement'));
488
+        return ($this->select('SHOW CREATE TABLE ' . $table)->fetchOne('statement'));
489 489
     }
490 490
 
491 491
     /**
@@ -545,17 +545,17 @@  discard block
 block discarded – undo
545 545
       */
546 546
     public function prepareInsertAssocBulk(array $values)
547 547
     {
548
-        if (isset($values[0]) && is_array($values[0])){ //случай, когда много строк вставляется
548
+        if (isset($values[0]) && is_array($values[0])) { //случай, когда много строк вставляется
549 549
             $preparedFields = array_keys($values[0]);
550 550
             $preparedValues = [];
551
-            foreach ($values as $idx => $row){
551
+            foreach ($values as $idx => $row) {
552 552
                 $_fields = array_keys($row);
553
-                if ($_fields !== $preparedFields){
554
-                    throw new QueryException("Fields not match: ".implode(',',$_fields)." and ".implode(',', $preparedFields)." on element $idx");
553
+                if ($_fields !== $preparedFields) {
554
+                    throw new QueryException("Fields not match: " . implode(',', $_fields) . " and " . implode(',', $preparedFields) . " on element $idx");
555 555
                 }
556 556
                 $preparedValues[] = array_values($row);
557 557
             }
558
-        }else{ //одна строка
558
+        } else { //одна строка
559 559
             $preparedFields = array_keys($values);
560 560
             $preparedValues = [array_values($values)];
561 561
         }
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
      */
589 589
     public function insertBatchTSVFiles($table_name, $file_names, $columns_array)
590 590
     {
591
-        return $this->insertBatchFiles($table_name,$file_names,$columns_array,'TabSeparated');
591
+        return $this->insertBatchFiles($table_name, $file_names, $columns_array, 'TabSeparated');
592 592
     }
593 593
 
594 594
     /**
@@ -601,17 +601,17 @@  discard block
 block discarded – undo
601 601
      * @return array
602 602
      * @throws Exception\TransportException
603 603
      */
604
-    public function insertBatchFiles($table_name, $file_names, $columns_array,$format="CSV")
604
+    public function insertBatchFiles($table_name, $file_names, $columns_array, $format = "CSV")
605 605
     {
606 606
         if (is_string($file_names))
607 607
         {
608
-            $file_names=[$file_names];
608
+            $file_names = [$file_names];
609 609
         }
610 610
         if ($this->getCountPendingQueue() > 0) {
611 611
             throw new QueryException('Queue must be empty, before insertBatch, need executeAsync');
612 612
         }
613 613
 
614
-        if (!in_array($format,$this->_support_format))
614
+        if (!in_array($format, $this->_support_format))
615 615
         {
616 616
             throw new QueryException('Format not support in insertBatchFiles');
617 617
         }
@@ -620,17 +620,17 @@  discard block
 block discarded – undo
620 620
 
621 621
         foreach ($file_names as $fileName) {
622 622
             if (!is_file($fileName) || !is_readable($fileName)) {
623
-                throw  new QueryException('Cant read file: ' . $fileName.' '.(is_file($fileName)?'':' is not file'));
623
+                throw  new QueryException('Cant read file: ' . $fileName . ' ' . (is_file($fileName) ? '' : ' is not file'));
624 624
             }
625 625
 
626 626
             if (!$columns_array)
627 627
             {
628
-                $sql = 'INSERT INTO ' . $table_name . ' FORMAT '.$format;
628
+                $sql = 'INSERT INTO ' . $table_name . ' FORMAT ' . $format;
629 629
 
630 630
             }
631 631
             else
632 632
             {
633
-                $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT '.$format;
633
+                $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT ' . $format;
634 634
 
635 635
             }
636 636
             $result[$fileName] = $this->transport()->writeAsyncCSV($sql, $fileName);
@@ -657,25 +657,25 @@  discard block
 block discarded – undo
657 657
      * @param string $format ['TabSeparated','TabSeparatedWithNames','CSV','CSVWithNames']
658 658
      * @return Transport\CurlerRequest
659 659
      */
660
-    public function insertBatchStream($table_name, $columns_array,$format="CSV")
660
+    public function insertBatchStream($table_name, $columns_array, $format = "CSV")
661 661
     {
662 662
         if ($this->getCountPendingQueue() > 0) {
663 663
             throw new QueryException('Queue must be empty, before insertBatch, need executeAsync');
664 664
         }
665 665
 
666
-        if (!in_array($format,$this->_support_format))
666
+        if (!in_array($format, $this->_support_format))
667 667
         {
668 668
             throw new QueryException('Format not support in insertBatchFiles');
669 669
         }
670 670
 
671 671
         if (!$columns_array)
672 672
         {
673
-            $sql = 'INSERT INTO ' . $table_name . ' FORMAT '.$format;
673
+            $sql = 'INSERT INTO ' . $table_name . ' FORMAT ' . $format;
674 674
 
675 675
         }
676 676
         else
677 677
         {
678
-            $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT '.$format;
678
+            $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT ' . $format;
679 679
 
680 680
         }
681 681
 
@@ -742,16 +742,16 @@  discard block
 block discarded – undo
742 742
      * @throws Exception\TransportException
743 743
      * @throws \Exception
744 744
      */
745
-    public function tablesSize($flatList=false)
745
+    public function tablesSize($flatList = false)
746 746
     {
747
-        $z=$this->select('
747
+        $z = $this->select('
748 748
             SELECT table,database,
749 749
             formatReadableSize(sum(bytes)) as size,
750 750
             sum(bytes) as sizebytes,
751 751
             min(min_date) as min_date,
752 752
             max(max_date) as max_date
753 753
             FROM system.parts 
754
-            WHERE active AND database=\''.$this->settings()->getDatabase().'\'
754
+            WHERE active AND database=\''.$this->settings()->getDatabase() . '\'
755 755
             GROUP BY table,database
756 756
         ');
757 757
 
@@ -774,12 +774,12 @@  discard block
 block discarded – undo
774 774
      * @throws Exception\TransportException
775 775
      * @throws \Exception
776 776
      */
777
-    public function isExists($database,$table)
777
+    public function isExists($database, $table)
778 778
     {
779 779
         return $this->select('
780 780
             SELECT *
781 781
             FROM system.tables 
782
-            WHERE name=\''.$table.'\' AND database=\''.$database.'\''
782
+            WHERE name=\''.$table . '\' AND database=\'' . $database . '\''
783 783
         )->rowsAsTree('name');
784 784
     }
785 785
 
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
         return $this->select('
799 799
             SELECT *
800 800
             FROM system.parts 
801
-            WHERE like(table,\'%' . $table . '%\') AND database=\''.$this->settings()->getDatabase().'\' 
801
+            WHERE like(table,\'%' . $table . '%\') AND database=\'' . $this->settings()->getDatabase() . '\' 
802 802
             ORDER BY max_date ' . ($limit > 0 ? ' LIMIT ' . intval($limit) : '')
803 803
         )->rowsAsTree('name');
804 804
     }
@@ -814,8 +814,8 @@  discard block
 block discarded – undo
814 814
     public function dropPartition($dataBaseTableName, $partition_id)
815 815
     {
816 816
 
817
-        $partition_id=trim($partition_id,'\'');
818
-        $this->settings()->set('replication_alter_partitions_sync',2);
817
+        $partition_id = trim($partition_id, '\'');
818
+        $this->settings()->set('replication_alter_partitions_sync', 2);
819 819
         $state = $this->write('ALTER TABLE {dataBaseTableName} DROP PARTITION :partion_id', [
820 820
             'dataBaseTableName'  => $dataBaseTableName,
821 821
             'partion_id' => $partition_id
@@ -833,12 +833,12 @@  discard block
 block discarded – undo
833 833
      */
834 834
     public function truncateTable($tableName)
835 835
     {
836
-        $partions=$this->partitions($tableName);
837
-        $out=[];
836
+        $partions = $this->partitions($tableName);
837
+        $out = [];
838 838
         foreach ($partions as $part_key=>$part)
839 839
         {
840
-            $part_id=$part['partition'];
841
-            $out[$part_id]=$this->dropPartition($tableName,$part_id);
840
+            $part_id = $part['partition'];
841
+            $out[$part_id] = $this->dropPartition($tableName, $part_id);
842 842
         }
843 843
         return $out;
844 844
     }
@@ -873,9 +873,9 @@  discard block
 block discarded – undo
873 873
             }
874 874
         }
875 875
 
876
-        $result=[];
876
+        $result = [];
877 877
         foreach ($drop as $partition_id) {
878
-            $result[$partition_id]=$this->dropPartition($table_name, $partition_id);
878
+            $result[$partition_id] = $this->dropPartition($table_name, $partition_id);
879 879
         }
880 880
 
881 881
         return $result;
Please login to merge, or discard this patch.
src/Query/Query.php 1 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/Query/WriteToFile.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
     const FORMAT_TabSeparatedWithNames = 'TabSeparatedWithNames';
14 14
     const FORMAT_CSV                   = 'CSV';
15 15
 
16
-    private $support_format=['TabSeparated','TabSeparatedWithNames','CSV'];
16
+    private $support_format = ['TabSeparated', 'TabSeparatedWithNames', 'CSV'];
17 17
     /**
18 18
      * @var string
19 19
      */
@@ -22,19 +22,19 @@  discard block
 block discarded – undo
22 22
     /**
23 23
      * @var string
24 24
      */
25
-    private $format='CSV';
25
+    private $format = 'CSV';
26 26
 
27 27
     /**
28 28
      * @var bool
29 29
      */
30
-    private $gzip=false;
30
+    private $gzip = false;
31 31
     /**
32 32
      * WriteToFile constructor.
33 33
      * @param string $file_name
34 34
      * @param bool $overwrite
35 35
      * @param null $format
36 36
      */
37
-    public function __construct($file_name,$overwrite=true,$format=null) {
37
+    public function __construct($file_name, $overwrite = true, $format = null) {
38 38
 
39 39
 
40 40
         if (!$file_name)
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
                 throw new QueryException('Can`t delete: ' . $file_name);
54 54
             }
55 55
         }
56
-        $dir=dirname($file_name);
56
+        $dir = dirname($file_name);
57 57
         if (!is_writable($dir))
58 58
         {
59 59
             throw new QueryException('Can`t writable dir: ' . $dir);
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         {
63 63
            $this->setFormat($format);
64 64
         }
65
-        $this->file_name=$file_name;
65
+        $this->file_name = $file_name;
66 66
     }
67 67
 
68 68
     /**
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
      */
79 79
     public function setGzip($flag)
80 80
     {
81
-        $this->gzip=$flag;
81
+        $this->gzip = $flag;
82 82
     }
83 83
 
84 84
     /**
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public function setFormat($format)
88 88
     {
89
-        if (!in_array($format,$this->support_format))
89
+        if (!in_array($format, $this->support_format))
90 90
         {
91 91
             throw new QueryException('Unsupport format: ' . $format);
92 92
         }
93
-        $this->format=$format;
93
+        $this->format = $format;
94 94
     }
95 95
     /**
96 96
      * @return int
Please login to merge, or discard this patch.
src/Transport/Http.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     /**
62 62
      * @var callable
63 63
      */
64
-    private $xClickHouseProgress=null;
64
+    private $xClickHouseProgress = null;
65 65
 
66 66
     /**
67 67
      * Http constructor.
@@ -113,10 +113,10 @@  discard block
 block discarded – undo
113 113
      */
114 114
     public function getUri()
115 115
     {
116
-        $proto='http';
117
-        if ($this->settings()->isHttps()) $proto='https';
116
+        $proto = 'http';
117
+        if ($this->settings()->isHttps()) $proto = 'https';
118 118
 
119
-        return $proto.'://' . $this->_host . ':' . $this->_port;
119
+        return $proto . '://' . $this->_host . ':' . $this->_port;
120 120
     }
121 121
 
122 122
     /**
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
         }
186 186
 
187 187
         $new->timeOut($this->settings()->getTimeOut());
188
-        $new->connectTimeOut($this->_connectTimeOut)->keepAlive();// one sec
188
+        $new->connectTimeOut($this->_connectTimeOut)->keepAlive(); // one sec
189 189
         $new->verbose(boolval($this->_verbose));
190 190
 
191 191
         return $new;
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         $request = $this->newRequest($extendinfo);
280 280
         $request->url($url);
281 281
 
282
-        $request->setCallbackFunction(function (CurlerRequest $request) {
282
+        $request->setCallbackFunction(function(CurlerRequest $request) {
283 283
             fclose($request->getInfileHandle());
284 284
         });
285 285
 
@@ -322,29 +322,29 @@  discard block
 block discarded – undo
322 322
 
323 323
     public function __findXClickHouseProgress($handle)
324 324
     {
325
-        $code=curl_getinfo($handle,CURLINFO_HTTP_CODE);
325
+        $code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
326 326
 
327 327
         // Search X-ClickHouse-Progress
328
-        if ($code==200) {
328
+        if ($code == 200) {
329 329
             $response = curl_multi_getcontent($handle);
330 330
             $header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
331 331
             if (!$header_size) return false;
332 332
 
333 333
             $header = substr($response, 0, $header_size);
334 334
             if (!$header_size) return false;
335
-            $pos=strrpos($header,'X-ClickHouse-Progress');
335
+            $pos = strrpos($header, 'X-ClickHouse-Progress');
336 336
 
337 337
             if (!$pos) return false;
338 338
 
339
-            $last=substr($header,$pos);
340
-            $data=@json_decode(str_ireplace('X-ClickHouse-Progress:','',$last),true);
339
+            $last = substr($header, $pos);
340
+            $data = @json_decode(str_ireplace('X-ClickHouse-Progress:', '', $last), true);
341 341
 
342 342
             if ($data && is_callable($this->xClickHouseProgress)) {
343 343
 
344
-                if (is_array($this->xClickHouseProgress)){
345
-                    call_user_func_array($this->xClickHouseProgress,[$data]);
344
+                if (is_array($this->xClickHouseProgress)) {
345
+                    call_user_func_array($this->xClickHouseProgress, [$data]);
346 346
                 } else {
347
-                    call_user_func($this->xClickHouseProgress,$data);
347
+                    call_user_func($this->xClickHouseProgress, $data);
348 348
                 }
349 349
 
350 350
 
@@ -407,13 +407,13 @@  discard block
 block discarded – undo
407 407
             }
408 408
 
409 409
 
410
-            $request->setResultFileHandle($fout, $isGz)->setCallbackFunction(function (CurlerRequest $request) {
410
+            $request->setResultFileHandle($fout, $isGz)->setCallbackFunction(function(CurlerRequest $request) {
411 411
                 fclose($request->getResultFileHandle());
412 412
             });
413 413
         }
414 414
         if ($this->xClickHouseProgress)
415 415
         {
416
-            $request->setFunctionProgress([$this,'__findXClickHouseProgress']);
416
+            $request->setFunctionProgress([$this, '__findXClickHouseProgress']);
417 417
         }
418 418
         // ---------------------------------------------------------------------------------
419 419
         return $request;
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
      */
544 544
     public function setProgressFunction(callable $callback)
545 545
     {
546
-        $this->xClickHouseProgress=$callback;
546
+        $this->xClickHouseProgress = $callback;
547 547
     }
548 548
 
549 549
     /**
Please login to merge, or discard this patch.