Completed
Push — master ( ad5c0d...b72b0b )
by Peter
02:35
created
src/Sphinx/Client.php 1 patch
Spacing   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 
418 418
     public function __destruct()
419 419
     {
420
-        if ($this->socket !== false) {
420
+        if ($this->socket!==false) {
421 421
             fclose($this->socket);
422 422
         }
423 423
     }
@@ -457,19 +457,19 @@  discard block
 block discarded – undo
457 457
     public function setServer($host, $port = 0)
458 458
     {
459 459
         assert(is_string($host));
460
-        if ($host[0] == '/') {
461
-            $this->path = 'unix://' . $host;
460
+        if ($host[0]=='/') {
461
+            $this->path = 'unix://'.$host;
462 462
             return;
463 463
         }
464
-        if (substr($host, 0, 7) == 'unix://') {
464
+        if (substr($host, 0, 7)=='unix://') {
465 465
             $this->path = $host;
466 466
             return;
467 467
         }
468 468
 
469 469
         $this->host = $host;
470 470
         $port = intval($port);
471
-        assert(0 <= $port && $port < 65536);
472
-        $this->port = $port == 0 ? 9312 : $port;
471
+        assert(0<=$port && $port<65536);
472
+        $this->port = $port==0 ? 9312 : $port;
473 473
         $this->path = '';
474 474
     }
475 475
 
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
      */
494 494
     protected function send($handle, $data, $length)
495 495
     {
496
-        if (feof($handle) || fwrite($handle, $data, $length) !== $length) {
496
+        if (feof($handle) || fwrite($handle, $data, $length)!==$length) {
497 497
             $this->error = 'connection unexpectedly closed (timed out?)';
498 498
             $this->conn_error = true;
499 499
             return false;
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
             $port = $this->port;
556 556
         }
557 557
 
558
-        if ($this->timeout <= 0) {
558
+        if ($this->timeout<=0) {
559 559
             $fp = @fsockopen($host, $port, $errno, $errstr);
560 560
         } else {
561 561
             $fp = @fsockopen($host, $port, $errno, $errstr, $this->timeout);
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
         // check version
588 588
         list(, $v) = unpack('N*', fread($fp, 4));
589 589
         $v = (int)$v;
590
-        if ($v < 1) {
590
+        if ($v<1) {
591 591
             fclose($fp);
592 592
             $this->error = "expected searchd protocol version 1+, got version '$v'";
593 593
             return false;
@@ -610,10 +610,10 @@  discard block
 block discarded – undo
610 610
         $len = 0;
611 611
 
612 612
         $header = fread($fp, 8);
613
-        if (strlen($header) == 8) {
613
+        if (strlen($header)==8) {
614 614
             list($status, $ver, $len) = array_values(unpack('n2a/Nb', $header));
615 615
             $left = $len;
616
-            while ($left > 0 && !feof($fp)) {
616
+            while ($left>0 && !feof($fp)) {
617 617
                 $chunk = fread($fp, min(8192, $left));
618 618
                 if ($chunk) {
619 619
                     $response .= $chunk;
@@ -622,13 +622,13 @@  discard block
 block discarded – undo
622 622
             }
623 623
         }
624 624
 
625
-        if ($this->socket === false) {
625
+        if ($this->socket===false) {
626 626
             fclose($fp);
627 627
         }
628 628
 
629 629
         // check response
630 630
         $read = strlen($response);
631
-        if (!$response || $read != $len) {
631
+        if (!$response || $read!=$len) {
632 632
             $this->error = $len
633 633
                 ? "failed to read searchd response (status=$status, ver=$ver, len=$len, read=$read)"
634 634
                 : 'received zero-sized searchd response';
@@ -641,13 +641,13 @@  discard block
 block discarded – undo
641 641
                 $this->warning = substr($response, 4, $wlen);
642 642
                 return substr($response, 4 + $wlen);
643 643
             case self::SEARCHD_ERROR:
644
-                $this->error = 'searchd error: ' . substr($response, 4);
644
+                $this->error = 'searchd error: '.substr($response, 4);
645 645
                 return false;
646 646
             case self::SEARCHD_RETRY:
647
-                $this->error = 'temporary searchd error: ' . substr($response, 4);
647
+                $this->error = 'temporary searchd error: '.substr($response, 4);
648 648
                 return false;
649 649
             case self::SEARCHD_OK:
650
-                if ($ver < $client_ver) { // check version
650
+                if ($ver<$client_ver) { // check version
651 651
                     $this->warning = sprintf(
652 652
                         'searchd command v.%d.%d older than client\'s v.%d.%d, some options might not work',
653 653
                         $ver >> 8,
@@ -680,15 +680,15 @@  discard block
 block discarded – undo
680 680
     {
681 681
         assert(is_int($offset));
682 682
         assert(is_int($limit));
683
-        assert($offset >= 0);
684
-        assert($limit > 0);
685
-        assert($max >= 0);
683
+        assert($offset>=0);
684
+        assert($limit>0);
685
+        assert($max>=0);
686 686
         $this->offset = $offset;
687 687
         $this->limit = $limit;
688
-        if ($max > 0) {
688
+        if ($max>0) {
689 689
             $this->max_matches = $max;
690 690
         }
691
-        if ($cutoff > 0) {
691
+        if ($cutoff>0) {
692 692
             $this->cutoff = $cutoff;
693 693
         }
694 694
     }
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
     public function setMaxQueryTime($max)
702 702
     {
703 703
         assert(is_int($max));
704
-        assert($max >= 0);
704
+        assert($max>=0);
705 705
         $this->max_query_time = $max;
706 706
     }
707 707
 
@@ -734,9 +734,9 @@  discard block
 block discarded – undo
734 734
      * @param int $ranker
735 735
      * @param string $rank_expr
736 736
      */
737
-    public function setRankingMode($ranker, $rank_expr='')
737
+    public function setRankingMode($ranker, $rank_expr = '')
738 738
     {
739
-        assert($ranker === 0 || $ranker >= 1 && $ranker < self::RANK_TOTAL);
739
+        assert($ranker===0 || $ranker>=1 && $ranker<self::RANK_TOTAL);
740 740
         assert(is_string($rank_expr));
741 741
         $this->ranker = $ranker;
742 742
         $this->rank_expr = $rank_expr;
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
             self::SORT_EXPR
760 760
         )));
761 761
         assert(is_string($sort_by));
762
-        assert($mode == self::SORT_RELEVANCE || strlen($sort_by) > 0);
762
+        assert($mode==self::SORT_RELEVANCE || strlen($sort_by)>0);
763 763
 
764 764
         $this->sort = $mode;
765 765
         $this->sort_by = $sort_by;
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
     {
814 814
         assert(is_numeric($min));
815 815
         assert(is_numeric($max));
816
-        assert($min <= $max);
816
+        assert($min<=$max);
817 817
 
818 818
         $this->min_id = $min;
819 819
         $this->max_id = $max;
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
         assert(is_string($attribute));
878 878
         assert(is_numeric($min));
879 879
         assert(is_numeric($max));
880
-        assert($min <= $max);
880
+        assert($min<=$max);
881 881
 
882 882
         $this->filters[] = array(
883 883
             'type' => self::FILTER_RANGE,
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
         assert(is_string($attribute));
903 903
         assert(is_float($min));
904 904
         assert(is_float($max));
905
-        assert($min <= $max);
905
+        assert($min<=$max);
906 906
 
907 907
         $this->filters[] = array(
908 908
             'type' => self::FILTER_FLOAT_RANGE,
@@ -982,8 +982,8 @@  discard block
 block discarded – undo
982 982
      */
983 983
     public function setRetries($count, $delay = 0)
984 984
     {
985
-        assert(is_int($count) && $count >= 0);
986
-        assert(is_int($delay) && $delay >= 0);
985
+        assert(is_int($count) && $count>=0);
986
+        assert(is_int($delay) && $delay>=0);
987 987
         $this->retry_count = $count;
988 988
         $this->retry_delay = $delay;
989 989
     }
@@ -1059,12 +1059,12 @@  discard block
 block discarded – undo
1059 1059
             'global_idf',
1060 1060
             'low_priority'
1061 1061
         );
1062
-        $flags = array (
1062
+        $flags = array(
1063 1063
             'reverse_scan' => array(0, 1),
1064 1064
             'sort_method' => array('pq', 'kbuffer'),
1065 1065
             'max_predicted_time' => array(0),
1066 1066
             'boolean_simplify' => array(true, false),
1067
-            'idf' => array ('normalized', 'plain', 'tfidf_normalized', 'tfidf_unnormalized'),
1067
+            'idf' => array('normalized', 'plain', 'tfidf_normalized', 'tfidf_unnormalized'),
1068 1068
             'global_idf' => array(true, false),
1069 1069
             'low_priority' => array(true, false)
1070 1070
         );
@@ -1072,29 +1072,29 @@  discard block
 block discarded – undo
1072 1072
         assert(isset($flag_name, $known_names));
1073 1073
         assert(
1074 1074
             in_array($flag_value, $flags[$flag_name], true) ||
1075
-            ($flag_name == 'max_predicted_time' && is_int($flag_value) && $flag_value >= 0)
1075
+            ($flag_name=='max_predicted_time' && is_int($flag_value) && $flag_value>=0)
1076 1076
         );
1077 1077
 
1078 1078
         switch ($flag_name) {
1079 1079
             case 'reverse_scan':
1080
-                $this->query_flags = setBit($this->query_flags, 0, $flag_value == 1);
1080
+                $this->query_flags = setBit($this->query_flags, 0, $flag_value==1);
1081 1081
                 break;
1082 1082
             case 'sort_method':
1083
-                $this->query_flags = setBit($this->query_flags, 1, $flag_value == 'kbuffer');
1083
+                $this->query_flags = setBit($this->query_flags, 1, $flag_value=='kbuffer');
1084 1084
                 break;
1085 1085
             case 'max_predicted_time':
1086
-                $this->query_flags = setBit($this->query_flags, 2, $flag_value > 0);
1086
+                $this->query_flags = setBit($this->query_flags, 2, $flag_value>0);
1087 1087
                 $this->predicted_time = (int)$flag_value;
1088 1088
                 break;
1089 1089
             case 'boolean_simplify':
1090 1090
                 $this->query_flags = setBit($this->query_flags, 3, $flag_value);
1091 1091
                 break;
1092 1092
             case 'idf':
1093
-                if ($flag_value == 'normalized' || $flag_value == 'plain') {
1094
-                    $this->query_flags = setBit($this->query_flags, 4, $flag_value == 'plain');
1093
+                if ($flag_value=='normalized' || $flag_value=='plain') {
1094
+                    $this->query_flags = setBit($this->query_flags, 4, $flag_value=='plain');
1095 1095
                 }
1096
-                if ($flag_value == 'tfidf_normalized' || $flag_value == 'tfidf_unnormalized') {
1097
-                    $this->query_flags = setBit($this->query_flags, 6, $flag_value == 'tfidf_normalized');
1096
+                if ($flag_value=='tfidf_normalized' || $flag_value=='tfidf_unnormalized') {
1097
+                    $this->query_flags = setBit($this->query_flags, 6, $flag_value=='tfidf_normalized');
1098 1098
                 }
1099 1099
                 break;
1100 1100
             case 'global_idf':
@@ -1118,8 +1118,8 @@  discard block
 block discarded – undo
1118 1118
         assert(is_string($order_by));
1119 1119
         assert(is_int($offset));
1120 1120
         assert(is_int($limit));
1121
-        assert($offset >= 0);
1122
-        assert($limit > 0);
1121
+        assert($offset>=0);
1122
+        assert($limit>0);
1123 1123
 
1124 1124
         $this->outer_order_by = $order_by;
1125 1125
         $this->outer_offset = $offset;
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
         $this->error = $results[0]['error'];
1199 1199
         $this->warning = $results[0]['warning'];
1200 1200
 
1201
-        if ($results[0]['status'] == self::SEARCHD_ERROR) {
1201
+        if ($results[0]['status']==self::SEARCHD_ERROR) {
1202 1202
             return false;
1203 1203
         } else {
1204 1204
             return $results[0];
@@ -1236,24 +1236,24 @@  discard block
 block discarded – undo
1236 1236
 
1237 1237
         // build request
1238 1238
         $req = pack('NNNNN', $this->query_flags, $this->offset, $this->limit, $this->mode, $this->ranker);
1239
-        if ($this->ranker == self::RANK_EXPR) {
1240
-            $req .= pack('N', strlen($this->rank_expr)) . $this->rank_expr;
1239
+        if ($this->ranker==self::RANK_EXPR) {
1240
+            $req .= pack('N', strlen($this->rank_expr)).$this->rank_expr;
1241 1241
         }
1242 1242
         $req .= pack('N', $this->sort); // (deprecated) sort mode
1243
-        $req .= pack('N', strlen($this->sort_by)) . $this->sort_by;
1244
-        $req .= pack('N', strlen($query)) . $query; // query itself
1243
+        $req .= pack('N', strlen($this->sort_by)).$this->sort_by;
1244
+        $req .= pack('N', strlen($query)).$query; // query itself
1245 1245
         $req .= pack('N', count($this->weights)); // weights
1246 1246
         foreach ($this->weights as $weight) {
1247 1247
             $req .= pack('N', (int)$weight);
1248 1248
         }
1249
-        $req .= pack('N', strlen($index)) . $index; // indexes
1249
+        $req .= pack('N', strlen($index)).$index; // indexes
1250 1250
         $req .= pack('N', 1); // id64 range marker
1251
-        $req .= pack64IntUnsigned($this->min_id) . pack64IntUnsigned($this->max_id); // id64 range
1251
+        $req .= pack64IntUnsigned($this->min_id).pack64IntUnsigned($this->max_id); // id64 range
1252 1252
 
1253 1253
         // filters
1254 1254
         $req .= pack('N', count($this->filters));
1255 1255
         foreach ($this->filters as $filter) {
1256
-            $req .= pack('N', strlen($filter['attr'])) . $filter['attr'];
1256
+            $req .= pack('N', strlen($filter['attr'])).$filter['attr'];
1257 1257
             $req .= pack('N', $filter['type']);
1258 1258
             switch ($filter['type']) {
1259 1259
                 case self::FILTER_VALUES:
@@ -1263,13 +1263,13 @@  discard block
 block discarded – undo
1263 1263
                     }
1264 1264
                     break;
1265 1265
                 case self::FILTER_RANGE:
1266
-                    $req .= pack64IntSigned($filter['min']) . pack64IntSigned($filter['max']);
1266
+                    $req .= pack64IntSigned($filter['min']).pack64IntSigned($filter['max']);
1267 1267
                     break;
1268 1268
                 case self::FILTER_FLOAT_RANGE:
1269
-                    $req .= $this->packFloat($filter['min']) . $this->packFloat($filter['max']);
1269
+                    $req .= $this->packFloat($filter['min']).$this->packFloat($filter['max']);
1270 1270
                     break;
1271 1271
                 case self::FILTER_STRING:
1272
-                    $req .= pack('N', strlen($filter['value'])) . $filter['value'];
1272
+                    $req .= pack('N', strlen($filter['value'])).$filter['value'];
1273 1273
                     break;
1274 1274
                 default:
1275 1275
                     assert(0 && 'internal error: unhandled filter type');
@@ -1278,27 +1278,27 @@  discard block
 block discarded – undo
1278 1278
         }
1279 1279
 
1280 1280
         // group-by clause, max-matches count, group-sort clause, cutoff count
1281
-        $req .= pack('NN', $this->group_func, strlen($this->group_by)) . $this->group_by;
1281
+        $req .= pack('NN', $this->group_func, strlen($this->group_by)).$this->group_by;
1282 1282
         $req .= pack('N', $this->max_matches);
1283
-        $req .= pack('N', strlen($this->group_sort)) . $this->group_sort;
1283
+        $req .= pack('N', strlen($this->group_sort)).$this->group_sort;
1284 1284
         $req .= pack('NNN', $this->cutoff, $this->retry_count, $this->retry_delay);
1285
-        $req .= pack('N', strlen($this->group_distinct)) . $this->group_distinct;
1285
+        $req .= pack('N', strlen($this->group_distinct)).$this->group_distinct;
1286 1286
 
1287 1287
         // anchor point
1288 1288
         if (empty($this->anchor)) {
1289 1289
             $req .= pack('N', 0);
1290 1290
         } else {
1291
-            $a =& $this->anchor;
1291
+            $a = & $this->anchor;
1292 1292
             $req .= pack('N', 1);
1293
-            $req .= pack('N', strlen($a['attrlat'])) . $a['attrlat'];
1294
-            $req .= pack('N', strlen($a['attrlong'])) . $a['attrlong'];
1295
-            $req .= $this->packFloat($a['lat']) . $this->packFloat($a['long']);
1293
+            $req .= pack('N', strlen($a['attrlat'])).$a['attrlat'];
1294
+            $req .= pack('N', strlen($a['attrlong'])).$a['attrlong'];
1295
+            $req .= $this->packFloat($a['lat']).$this->packFloat($a['long']);
1296 1296
         }
1297 1297
 
1298 1298
         // per-index weights
1299 1299
         $req .= pack('N', count($this->index_weights));
1300 1300
         foreach ($this->index_weights as $idx => $weight) {
1301
-            $req .= pack('N', strlen($idx)) . $idx . pack('N', $weight);
1301
+            $req .= pack('N', strlen($idx)).$idx.pack('N', $weight);
1302 1302
         }
1303 1303
 
1304 1304
         // max query time
@@ -1307,16 +1307,16 @@  discard block
 block discarded – undo
1307 1307
         // per-field weights
1308 1308
         $req .= pack('N', count($this->field_weights));
1309 1309
         foreach ($this->field_weights as $field => $weight) {
1310
-            $req .= pack('N', strlen($field)) . $field . pack('N', $weight);
1310
+            $req .= pack('N', strlen($field)).$field.pack('N', $weight);
1311 1311
         }
1312 1312
 
1313 1313
         // comment
1314
-        $req .= pack('N', strlen($comment)) . $comment;
1314
+        $req .= pack('N', strlen($comment)).$comment;
1315 1315
 
1316 1316
         // attribute overrides
1317 1317
         $req .= pack('N', count($this->overrides));
1318 1318
         foreach ($this->overrides as $key => $entry) {
1319
-            $req .= pack('N', strlen($entry['attr'])) . $entry['attr'];
1319
+            $req .= pack('N', strlen($entry['attr'])).$entry['attr'];
1320 1320
             $req .= pack('NN', $entry['type'], count($entry['values']));
1321 1321
             foreach ($entry['values'] as $id => $val) {
1322 1322
                 assert(is_numeric($id));
@@ -1338,14 +1338,14 @@  discard block
 block discarded – undo
1338 1338
         }
1339 1339
 
1340 1340
         // select-list
1341
-        $req .= pack('N', strlen($this->select)) . $this->select;
1341
+        $req .= pack('N', strlen($this->select)).$this->select;
1342 1342
 
1343 1343
         // max_predicted_time
1344
-        if ($this->predicted_time > 0) {
1344
+        if ($this->predicted_time>0) {
1345 1345
             $req .= pack('N', (int)$this->predicted_time);
1346 1346
         }
1347 1347
 
1348
-        $req .= pack('N', strlen($this->outer_order_by)) . $this->outer_order_by;
1348
+        $req .= pack('N', strlen($this->outer_order_by)).$this->outer_order_by;
1349 1349
         $req .= pack('NN', $this->outer_offset, $this->outer_limit);
1350 1350
         if ($this->has_outer) {
1351 1351
             $req .= pack('N', 1);
@@ -1376,7 +1376,7 @@  discard block
 block discarded – undo
1376 1376
         // mbstring workaround
1377 1377
         $this->mbPush();
1378 1378
 
1379
-        if (($fp = $this->connect()) === false) {
1379
+        if (($fp = $this->connect())===false) {
1380 1380
             $this->mbPop();
1381 1381
             return false;
1382 1382
         }
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
         $req = join('', $this->reqs);
1387 1387
         $len = 8 + strlen($req);
1388 1388
         // add header
1389
-        $req = pack('nnNNN', self::SEARCHD_COMMAND_SEARCH, self::VER_COMMAND_SEARCH, $len, 0, $nreqs) . $req;
1389
+        $req = pack('nnNNN', self::SEARCHD_COMMAND_SEARCH, self::VER_COMMAND_SEARCH, $len, 0, $nreqs).$req;
1390 1390
 
1391 1391
         if (!$this->send($fp, $req, $len + 8) || !($response = $this->getResponse($fp, self::VER_COMMAND_SEARCH))) {
1392 1392
             $this->mbPop();
@@ -1414,9 +1414,9 @@  discard block
 block discarded – undo
1414 1414
         $max = strlen($response); // max position for checks, to protect against broken responses
1415 1415
 
1416 1416
         $results = array();
1417
-        for ($ires = 0; $ires < $nreqs && $p < $max; $ires++) {
1417
+        for ($ires = 0; $ires<$nreqs && $p<$max; $ires++) {
1418 1418
             $results[] = array();
1419
-            $result =& $results[$ires];
1419
+            $result = & $results[$ires];
1420 1420
 
1421 1421
             $result['error'] = '';
1422 1422
             $result['warning'] = '';
@@ -1425,13 +1425,13 @@  discard block
 block discarded – undo
1425 1425
             list(, $status) = unpack('N*', substr($response, $p, 4));
1426 1426
             $p += 4;
1427 1427
             $result['status'] = $status;
1428
-            if ($status != self::SEARCHD_OK) {
1428
+            if ($status!=self::SEARCHD_OK) {
1429 1429
                 list(, $len) = unpack('N*', substr($response, $p, 4));
1430 1430
                 $p += 4;
1431 1431
                 $message = substr($response, $p, $len);
1432 1432
                 $p += $len;
1433 1433
 
1434
-                if ($status == self::SEARCHD_WARNING) {
1434
+                if ($status==self::SEARCHD_WARNING) {
1435 1435
                     $result['warning'] = $message;
1436 1436
                 } else {
1437 1437
                     $result['error'] = $message;
@@ -1445,7 +1445,7 @@  discard block
 block discarded – undo
1445 1445
 
1446 1446
             list(, $nfields) = unpack('N*', substr($response, $p, 4));
1447 1447
             $p += 4;
1448
-            while ($nfields --> 0 && $p < $max) {
1448
+            while ($nfields-->0 && $p<$max) {
1449 1449
                 list(, $len) = unpack('N*', substr($response, $p, 4));
1450 1450
                 $p += 4;
1451 1451
                 $fields[] = substr($response, $p, $len);
@@ -1455,7 +1455,7 @@  discard block
 block discarded – undo
1455 1455
 
1456 1456
             list(, $n_attrs) = unpack('N*', substr($response, $p, 4));
1457 1457
             $p += 4;
1458
-            while ($n_attrs --> 0 && $p < $max) {
1458
+            while ($n_attrs-->0 && $p<$max) {
1459 1459
                 list(, $len) = unpack('N*', substr($response, $p, 4));
1460 1460
                 $p += 4;
1461 1461
                 $attr = substr($response, $p, $len);
@@ -1474,7 +1474,7 @@  discard block
 block discarded – undo
1474 1474
 
1475 1475
             // read matches
1476 1476
             $idx = -1;
1477
-            while ($count --> 0 && $p < $max) {
1477
+            while ($count-->0 && $p<$max) {
1478 1478
                 // index into result array
1479 1479
                 $idx++;
1480 1480
 
@@ -1502,14 +1502,14 @@  discard block
 block discarded – undo
1502 1502
                 $attr_values = array();
1503 1503
                 foreach ($attrs as $attr => $type) {
1504 1504
                     // handle 64bit int
1505
-                    if ($type == self::ATTR_BIGINT) {
1505
+                    if ($type==self::ATTR_BIGINT) {
1506 1506
                         $attr_values[$attr] = unpack64IntSigned(substr($response, $p, 8));
1507 1507
                         $p += 8;
1508 1508
                         continue;
1509 1509
                     }
1510 1510
 
1511 1511
                     // handle floats
1512
-                    if ($type == self::ATTR_FLOAT) {
1512
+                    if ($type==self::ATTR_FLOAT) {
1513 1513
                         list(, $u_value) = unpack('N*', substr($response, $p, 4));
1514 1514
                         $p += 4;
1515 1515
                         list(, $f_value) = unpack('f*', pack('L', $u_value));
@@ -1520,28 +1520,28 @@  discard block
 block discarded – undo
1520 1520
                     // handle everything else as unsigned int
1521 1521
                     list(, $val) = unpack('N*', substr($response, $p, 4));
1522 1522
                     $p += 4;
1523
-                    if ($type == self::ATTR_MULTI) {
1523
+                    if ($type==self::ATTR_MULTI) {
1524 1524
                         $attr_values[$attr] = array();
1525 1525
                         $n_values = $val;
1526
-                        while ($n_values --> 0 && $p < $max) {
1526
+                        while ($n_values-->0 && $p<$max) {
1527 1527
                             list(, $val) = unpack('N*', substr($response, $p, 4));
1528 1528
                             $p += 4;
1529 1529
                             $attr_values[$attr][] = fixUInt($val);
1530 1530
                         }
1531
-                    } elseif ($type == self::ATTR_MULTI64) {
1531
+                    } elseif ($type==self::ATTR_MULTI64) {
1532 1532
                         $attr_values[$attr] = array();
1533 1533
                         $n_values = $val;
1534
-                        while ($n_values > 0 && $p < $max) {
1534
+                        while ($n_values>0 && $p<$max) {
1535 1535
                             $attr_values[$attr][] = unpack64IntSigned(substr($response, $p, 8));
1536 1536
                             $p += 8;
1537 1537
                             $n_values -= 2;
1538 1538
                         }
1539
-                    } elseif ($type == self::ATTR_STRING) {
1539
+                    } elseif ($type==self::ATTR_STRING) {
1540 1540
                         $attr_values[$attr] = substr($response, $p, $val);
1541 1541
                         $p += $val;
1542
-                    } elseif ($type == self::ATTR_FACTORS) {
1542
+                    } elseif ($type==self::ATTR_FACTORS) {
1543 1543
                         $attr_values[$attr] = substr($response, $p, $val - 4);
1544
-                        $p += $val-4;
1544
+                        $p += $val - 4;
1545 1545
                     } else {
1546 1546
                         $attr_values[$attr] = fixUInt($val);
1547 1547
                     }
@@ -1560,14 +1560,14 @@  discard block
 block discarded – undo
1560 1560
             $result['time'] = sprintf('%.3f', $msecs / 1000);
1561 1561
             $p += 16;
1562 1562
 
1563
-            while ($words --> 0 && $p < $max) {
1563
+            while ($words-->0 && $p<$max) {
1564 1564
                 list(, $len) = unpack('N*', substr($response, $p, 4));
1565 1565
                 $p += 4;
1566 1566
                 $word = substr($response, $p, $len);
1567 1567
                 $p += $len;
1568 1568
                 list($docs, $hits) = array_values(unpack('N*N*', substr($response, $p, 8)));
1569 1569
                 $p += 8;
1570
-                $result['words'][$word] = array (
1570
+                $result['words'][$word] = array(
1571 1571
                     'docs' => sprintf('%u', $docs),
1572 1572
                     'hits' => sprintf('%u', $hits)
1573 1573
                 );
@@ -1600,7 +1600,7 @@  discard block
 block discarded – undo
1600 1600
 
1601 1601
         $this->mbPush();
1602 1602
 
1603
-        if (($fp = $this->connect()) === false) {
1603
+        if (($fp = $this->connect())===false) {
1604 1604
             $this->mbPop();
1605 1605
             return false;
1606 1606
         }
@@ -1669,24 +1669,24 @@  discard block
 block discarded – undo
1669 1669
             $flags |= 1024;
1670 1670
         }
1671 1671
         $req = pack('NN', 0, $flags); // mode=0, flags=$flags
1672
-        $req .= pack('N', strlen($index)) . $index; // req index
1673
-        $req .= pack('N', strlen($words)) . $words; // req words
1672
+        $req .= pack('N', strlen($index)).$index; // req index
1673
+        $req .= pack('N', strlen($words)).$words; // req words
1674 1674
 
1675 1675
         // options
1676
-        $req .= pack('N', strlen($opts['before_match'])) . $opts['before_match'];
1677
-        $req .= pack('N', strlen($opts['after_match'])) . $opts['after_match'];
1678
-        $req .= pack('N', strlen($opts['chunk_separator'])) . $opts['chunk_separator'];
1676
+        $req .= pack('N', strlen($opts['before_match'])).$opts['before_match'];
1677
+        $req .= pack('N', strlen($opts['after_match'])).$opts['after_match'];
1678
+        $req .= pack('N', strlen($opts['chunk_separator'])).$opts['chunk_separator'];
1679 1679
         $req .= pack('NN', (int)$opts['limit'], (int)$opts['around']);
1680 1680
         // v.1.2
1681 1681
         $req .= pack('NNN', (int)$opts['limit_passages'], (int)$opts['limit_words'], (int)$opts['start_passage_id']);
1682
-        $req .= pack('N', strlen($opts['html_strip_mode'])) . $opts['html_strip_mode'];
1683
-        $req .= pack('N', strlen($opts['passage_boundary'])) . $opts['passage_boundary'];
1682
+        $req .= pack('N', strlen($opts['html_strip_mode'])).$opts['html_strip_mode'];
1683
+        $req .= pack('N', strlen($opts['passage_boundary'])).$opts['passage_boundary'];
1684 1684
 
1685 1685
         // documents
1686 1686
         $req .= pack('N', count($docs));
1687 1687
         foreach ($docs as $doc) {
1688 1688
             assert(is_string($doc));
1689
-            $req .= pack('N', strlen($doc)) . $doc;
1689
+            $req .= pack('N', strlen($doc)).$doc;
1690 1690
         }
1691 1691
 
1692 1692
         ////////////////////////////
@@ -1694,7 +1694,7 @@  discard block
 block discarded – undo
1694 1694
         ////////////////////////////
1695 1695
 
1696 1696
         $len = strlen($req);
1697
-        $req = pack('nnN', self::SEARCHD_COMMAND_EXCERPT, self::VER_COMMAND_EXCERPT, $len) . $req; // add header
1697
+        $req = pack('nnN', self::SEARCHD_COMMAND_EXCERPT, self::VER_COMMAND_EXCERPT, $len).$req; // add header
1698 1698
         if (!$this->send($fp, $req, $len + 8) || !($response = $this->getResponse($fp, self::VER_COMMAND_EXCERPT))) {
1699 1699
             $this->mbPop();
1700 1700
             return false;
@@ -1712,7 +1712,7 @@  discard block
 block discarded – undo
1712 1712
             list(, $len) = unpack('N*', substr($response, $pos, 4));
1713 1713
             $pos += 4;
1714 1714
 
1715
-            if ($pos + $len > $rlen) {
1715
+            if ($pos + $len>$rlen) {
1716 1716
                 $this->error = 'incomplete reply';
1717 1717
                 $this->mbPop();
1718 1718
                 return false;
@@ -1748,7 +1748,7 @@  discard block
 block discarded – undo
1748 1748
 
1749 1749
         $this->mbPush();
1750 1750
 
1751
-        if (($fp = $this->connect()) === false) {
1751
+        if (($fp = $this->connect())===false) {
1752 1752
             $this->mbPop();
1753 1753
             return false;
1754 1754
         }
@@ -1758,8 +1758,8 @@  discard block
 block discarded – undo
1758 1758
         /////////////////
1759 1759
 
1760 1760
         // v.1.0 req
1761
-        $req  = pack('N', strlen($query)) . $query; // req query
1762
-        $req .= pack('N', strlen($index)) . $index; // req index
1761
+        $req  = pack('N', strlen($query)).$query; // req query
1762
+        $req .= pack('N', strlen($index)).$index; // req index
1763 1763
         $req .= pack('N', (int)$hits);
1764 1764
 
1765 1765
         ////////////////////////////
@@ -1767,7 +1767,7 @@  discard block
 block discarded – undo
1767 1767
         ////////////////////////////
1768 1768
 
1769 1769
         $len = strlen($req);
1770
-        $req = pack('nnN', self::SEARCHD_COMMAND_KEYWORDS, self::VER_COMMAND_KEYWORDS, $len) . $req; // add header
1770
+        $req = pack('nnN', self::SEARCHD_COMMAND_KEYWORDS, self::VER_COMMAND_KEYWORDS, $len).$req; // add header
1771 1771
         if (!$this->send($fp, $req, $len + 8) || !($response = $this->getResponse($fp, self::VER_COMMAND_KEYWORDS))) {
1772 1772
             $this->mbPop();
1773 1773
             return false;
@@ -1782,7 +1782,7 @@  discard block
 block discarded – undo
1782 1782
         $rlen = strlen($response);
1783 1783
         list(, $nwords) = unpack('N*', substr($response, $pos, 4));
1784 1784
         $pos += 4;
1785
-        for ($i = 0; $i < $nwords; $i++) {
1785
+        for ($i = 0; $i<$nwords; $i++) {
1786 1786
             list(, $len) = unpack('N*', substr($response, $pos, 4));
1787 1787
             $pos += 4;
1788 1788
             $tokenized = $len ? substr($response, $pos, $len) : '';
@@ -1805,7 +1805,7 @@  discard block
 block discarded – undo
1805 1805
                 $res[$i]['hits'] = $nhits;
1806 1806
             }
1807 1807
 
1808
-            if ($pos > $rlen) {
1808
+            if ($pos>$rlen) {
1809 1809
                 $this->error = 'incomplete reply';
1810 1810
                 $this->mbPop();
1811 1811
                 return false;
@@ -1823,8 +1823,8 @@  discard block
 block discarded – undo
1823 1823
      */
1824 1824
     public function escapeString($string)
1825 1825
     {
1826
-        $from = array('\\', '(',')','|','-','!','@','~','"','&', '/', '^', '$', '=', '<');
1827
-        $to   = array('\\\\', '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/', '\^', '\$', '\=', '\<');
1826
+        $from = array('\\', '(', ')', '|', '-', '!', '@', '~', '"', '&', '/', '^', '$', '=', '<');
1827
+        $to   = array('\\\\', '\(', '\)', '\|', '\-', '\!', '\@', '\~', '\"', '\&', '\/', '\^', '\$', '\=', '\<');
1828 1828
 
1829 1829
         return str_replace($from, $to, $string);
1830 1830
     }
@@ -1859,7 +1859,7 @@  discard block
 block discarded – undo
1859 1859
         foreach ($values as $id => $entry) {
1860 1860
             assert(is_numeric($id));
1861 1861
             assert(is_array($entry));
1862
-            assert(count($entry) == count($attrs));
1862
+            assert(count($entry)==count($attrs));
1863 1863
             foreach ($entry as $v) {
1864 1864
                 if ($mva) {
1865 1865
                     assert(is_array($v));
@@ -1874,12 +1874,12 @@  discard block
 block discarded – undo
1874 1874
 
1875 1875
         // build request
1876 1876
         $this->mbPush();
1877
-        $req = pack('N', strlen($index)) . $index;
1877
+        $req = pack('N', strlen($index)).$index;
1878 1878
 
1879 1879
         $req .= pack('N', count($attrs));
1880 1880
         $req .= pack('N', $ignore_non_existent ? 1 : 0);
1881 1881
         foreach ($attrs as $attr) {
1882
-            $req .= pack('N', strlen($attr)) . $attr;
1882
+            $req .= pack('N', strlen($attr)).$attr;
1883 1883
             $req .= pack('N', $mva ? 1 : 0);
1884 1884
         }
1885 1885
 
@@ -1897,13 +1897,13 @@  discard block
 block discarded – undo
1897 1897
         }
1898 1898
 
1899 1899
         // connect, send query, get response
1900
-        if (($fp = $this->connect()) === false) {
1900
+        if (($fp = $this->connect())===false) {
1901 1901
             $this->mbPop();
1902 1902
             return -1;
1903 1903
         }
1904 1904
 
1905 1905
         $len = strlen($req);
1906
-        $req = pack('nnN', self::SEARCHD_COMMAND_UPDATE, self::VER_COMMAND_UPDATE, $len) . $req; // add header
1906
+        $req = pack('nnN', self::SEARCHD_COMMAND_UPDATE, self::VER_COMMAND_UPDATE, $len).$req; // add header
1907 1907
         if (!$this->send($fp, $req, $len + 8)) {
1908 1908
             $this->mbPop();
1909 1909
             return -1;
@@ -1929,11 +1929,11 @@  discard block
 block discarded – undo
1929 1929
      */
1930 1930
     public function open()
1931 1931
     {
1932
-        if ($this->socket !== false) {
1932
+        if ($this->socket!==false) {
1933 1933
             $this->error = 'already connected';
1934 1934
             return false;
1935 1935
         }
1936
-        if (($fp = $this->connect()) === false)
1936
+        if (($fp = $this->connect())===false)
1937 1937
             return false;
1938 1938
 
1939 1939
         // command, command version = 0, body length = 4, body = 1
@@ -1951,7 +1951,7 @@  discard block
 block discarded – undo
1951 1951
      */
1952 1952
     public function close()
1953 1953
     {
1954
-        if ($this->socket === false) {
1954
+        if ($this->socket===false) {
1955 1955
             $this->error = 'not connected';
1956 1956
             return false;
1957 1957
         }
@@ -1976,7 +1976,7 @@  discard block
 block discarded – undo
1976 1976
         assert(is_bool($session));
1977 1977
 
1978 1978
         $this->mbPush();
1979
-        if (($fp = $this->connect()) === false) {
1979
+        if (($fp = $this->connect())===false) {
1980 1980
             $this->mbPop();
1981 1981
             return false;
1982 1982
         }
@@ -1994,8 +1994,8 @@  discard block
 block discarded – undo
1994 1994
         $p += 8;
1995 1995
 
1996 1996
         $res = array();
1997
-        for ($i = 0; $i < $rows; $i++) {
1998
-            for ($j = 0; $j < $cols; $j++) {
1997
+        for ($i = 0; $i<$rows; $i++) {
1998
+            for ($j = 0; $j<$cols; $j++) {
1999 1999
                 list(, $len) = unpack('N*', substr($response, $p, 4));
2000 2000
                 $p += 4;
2001 2001
                 $res[$i][] = substr($response, $p, $len);
@@ -2017,7 +2017,7 @@  discard block
 block discarded – undo
2017 2017
     public function flushAttributes()
2018 2018
     {
2019 2019
         $this->mbPush();
2020
-        if (($fp = $this->connect()) === false) {
2020
+        if (($fp = $this->connect())===false) {
2021 2021
             $this->mbPop();
2022 2022
             return -1;
2023 2023
         }
@@ -2029,7 +2029,7 @@  discard block
 block discarded – undo
2029 2029
         }
2030 2030
 
2031 2031
         $tag = -1;
2032
-        if (strlen($response) == 4) {
2032
+        if (strlen($response)==4) {
2033 2033
             list(, $tag) = unpack('N*', $response);
2034 2034
         } else {
2035 2035
             $this->error = 'unexpected response length';
Please login to merge, or discard this patch.