Completed
Pull Request — master (#57)
by Elan
03:18
created
src/Client.php 1 patch
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -130,10 +130,10 @@  discard block
 block discarded – undo
130 130
             $server = $parts['host'];
131 131
             $path = isset($parts['path']) ? $parts['path'] : '';
132 132
             if (isset($parts['query'])) {
133
-                $path .= '?' . $parts['query'];
133
+                $path .= '?'.$parts['query'];
134 134
             }
135 135
             if (isset($parts['fragment'])) {
136
-                $path .= '#' . $parts['fragment'];
136
+                $path .= '#'.$parts['fragment'];
137 137
             }
138 138
             if (isset($parts['port'])) {
139 139
                 $port = $parts['port'];
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
             }
150 150
         }
151 151
         if ($path == '' || $path[0] != '/') {
152
-            $this->path = '/' . $path;
152
+            $this->path = '/'.$path;
153 153
         } else {
154 154
             $this->path = $path;
155 155
         }
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
         }*/
188 188
 
189 189
         // initialize user_agent string
190
-        $this->user_agent = PhpXmlRpc::$xmlrpcName . '/' . PhpXmlRpc::$xmlrpcVersion;
190
+        $this->user_agent = PhpXmlRpc::$xmlrpcName.'/'.PhpXmlRpc::$xmlrpcVersion;
191 191
     }
192 192
 
193 193
     /**
@@ -556,10 +556,10 @@  discard block
 block discarded – undo
556 556
      */
557 557
     protected function sendPayloadHTTP10($req, $server, $port, $timeout = 0, $username = '', $password = '',
558 558
         $authType = 1, $proxyHost = '', $proxyPort = 0, $proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1,
559
-        $method='http')
559
+        $method = 'http')
560 560
     {
561 561
         if ($port == 0) {
562
-            $port = ( $method === "https" ) ? 443 : 80;
562
+            $port = ($method === "https") ? 443 : 80;
563 563
         }
564 564
 
565 565
         // Only create the payload if it was not created previously
@@ -590,15 +590,15 @@  discard block
 block discarded – undo
590 590
         // thanks to Grant Rauscher <[email protected]> for this
591 591
         $credentials = '';
592 592
         if ($username != '') {
593
-            $credentials = 'Authorization: Basic ' . base64_encode($username . ':' . $password) . "\r\n";
593
+            $credentials = 'Authorization: Basic '.base64_encode($username.':'.$password)."\r\n";
594 594
             if ($authType != 1) {
595
-                error_log('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported with HTTP 1.0');
595
+                error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth is supported with HTTP 1.0');
596 596
             }
597 597
         }
598 598
 
599 599
         $acceptedEncoding = '';
600 600
         if (is_array($this->accepted_compression) && count($this->accepted_compression)) {
601
-            $acceptedEncoding = 'Accept-Encoding: ' . implode(', ', $this->accepted_compression) . "\r\n";
601
+            $acceptedEncoding = 'Accept-Encoding: '.implode(', ', $this->accepted_compression)."\r\n";
602 602
         }
603 603
 
604 604
         $proxyCredentials = '';
@@ -609,18 +609,18 @@  discard block
 block discarded – undo
609 609
             $connectServer = $proxyHost;
610 610
             $connectPort = $proxyPort;
611 611
             $transport = "tcp";
612
-            $uri = 'http://' . $server . ':' . $port . $this->path;
612
+            $uri = 'http://'.$server.':'.$port.$this->path;
613 613
             if ($proxyUsername != '') {
614 614
                 if ($proxyAuthType != 1) {
615
-                    error_log('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth to proxy is supported with HTTP 1.0');
615
+                    error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth to proxy is supported with HTTP 1.0');
616 616
                 }
617
-                $proxyCredentials = 'Proxy-Authorization: Basic ' . base64_encode($proxyUsername . ':' . $proxyPassword) . "\r\n";
617
+                $proxyCredentials = 'Proxy-Authorization: Basic '.base64_encode($proxyUsername.':'.$proxyPassword)."\r\n";
618 618
             }
619 619
         } else {
620 620
             $connectServer = $server;
621 621
             $connectPort = $port;
622 622
             /// @todo if supporting https, we should support all its current options as well: peer name verification etc...
623
-            $transport = ( $method === "https" ) ? "tls" : "tcp";
623
+            $transport = ($method === "https") ? "tls" : "tcp";
624 624
             $uri = $this->path;
625 625
         }
626 626
 
@@ -631,56 +631,56 @@  discard block
 block discarded – undo
631 631
             $version = '';
632 632
             foreach ($this->cookies as $name => $cookie) {
633 633
                 if ($cookie['version']) {
634
-                    $version = ' $Version="' . $cookie['version'] . '";';
635
-                    $cookieHeader .= ' ' . $name . '="' . $cookie['value'] . '";';
634
+                    $version = ' $Version="'.$cookie['version'].'";';
635
+                    $cookieHeader .= ' '.$name.'="'.$cookie['value'].'";';
636 636
                     if ($cookie['path']) {
637
-                        $cookieHeader .= ' $Path="' . $cookie['path'] . '";';
637
+                        $cookieHeader .= ' $Path="'.$cookie['path'].'";';
638 638
                     }
639 639
                     if ($cookie['domain']) {
640
-                        $cookieHeader .= ' $Domain="' . $cookie['domain'] . '";';
640
+                        $cookieHeader .= ' $Domain="'.$cookie['domain'].'";';
641 641
                     }
642 642
                     if ($cookie['port']) {
643
-                        $cookieHeader .= ' $Port="' . $cookie['port'] . '";';
643
+                        $cookieHeader .= ' $Port="'.$cookie['port'].'";';
644 644
                     }
645 645
                 } else {
646
-                    $cookieHeader .= ' ' . $name . '=' . $cookie['value'] . ";";
646
+                    $cookieHeader .= ' '.$name.'='.$cookie['value'].";";
647 647
                 }
648 648
             }
649
-            $cookieHeader = 'Cookie:' . $version . substr($cookieHeader, 0, -1) . "\r\n";
649
+            $cookieHeader = 'Cookie:'.$version.substr($cookieHeader, 0, -1)."\r\n";
650 650
         }
651 651
 
652 652
         // omit port if 80
653
-        $port = ($port == 80) ? '' : (':' . $port);
654
-
655
-        $op = 'POST ' . $uri . " HTTP/1.0\r\n" .
656
-            'User-Agent: ' . $this->user_agent . "\r\n" .
657
-            'Host: ' . $server . $port . "\r\n" .
658
-            $credentials .
659
-            $proxyCredentials .
660
-            $acceptedEncoding .
661
-            $encodingHdr .
662
-            'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings) . "\r\n" .
663
-            $cookieHeader .
664
-            'Content-Type: ' . $req->content_type . "\r\nContent-Length: " .
665
-            strlen($payload) . "\r\n\r\n" .
653
+        $port = ($port == 80) ? '' : (':'.$port);
654
+
655
+        $op = 'POST '.$uri." HTTP/1.0\r\n".
656
+            'User-Agent: '.$this->user_agent."\r\n".
657
+            'Host: '.$server.$port."\r\n".
658
+            $credentials.
659
+            $proxyCredentials.
660
+            $acceptedEncoding.
661
+            $encodingHdr.
662
+            'Accept-Charset: '.implode(',', $this->accepted_charset_encodings)."\r\n".
663
+            $cookieHeader.
664
+            'Content-Type: '.$req->content_type."\r\nContent-Length: ".
665
+            strlen($payload)."\r\n\r\n".
666 666
             $payload;
667 667
 
668
-        if ($this->debug > 1) {
668
+        if ($this->debug>1) {
669 669
             Logger::instance()->debugMessage("---SENDING---\n$op\n---END---");
670 670
         }
671 671
 
672
-        if ($timeout > 0) {
672
+        if ($timeout>0) {
673 673
             $fp = @stream_socket_client("$transport://$connectServer:$connectPort", $this->errno, $this->errstr, $timeout);
674 674
         } else {
675 675
             $fp = @stream_socket_client("$transport://$connectServer:$connectPort", $this->errno, $this->errstr);
676 676
         }
677 677
         if ($fp) {
678
-            if ($timeout > 0) {
678
+            if ($timeout>0) {
679 679
                 stream_set_timeout($fp, $timeout);
680 680
             }
681 681
         } else {
682
-            $this->errstr = 'Connect error: ' . $this->errstr;
683
-            $r = new Response(0, PhpXmlRpc::$xmlrpcerr['http_error'], $this->errstr . ' (' . $this->errno . ')');
682
+            $this->errstr = 'Connect error: '.$this->errstr;
683
+            $r = new Response(0, PhpXmlRpc::$xmlrpcerr['http_error'], $this->errstr.' ('.$this->errno.')');
684 684
 
685 685
             return $r;
686 686
         }
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
      * @param int $sslVersion
733 733
      * @return Response
734 734
      */
735
-    protected function sendPayloadHTTPS($req, $server, $port, $timeout = 0, $username = '',  $password = '',
735
+    protected function sendPayloadHTTPS($req, $server, $port, $timeout = 0, $username = '', $password = '',
736 736
         $authType = 1, $cert = '', $certPass = '', $caCert = '', $caCertDir = '', $proxyHost = '', $proxyPort = 0,
737 737
         $proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1, $keepAlive = false, $key = '', $keyPass = '',
738 738
         $sslVersion = 0)
@@ -821,12 +821,12 @@  discard block
 block discarded – undo
821 821
             $encodingHdr = '';
822 822
         }
823 823
 
824
-        if ($this->debug > 1) {
824
+        if ($this->debug>1) {
825 825
             Logger::instance()->debugMessage("---SENDING---\n$payload\n---END---");
826 826
         }
827 827
 
828 828
         if (!$keepAlive || !$this->xmlrpc_curl_handle) {
829
-            $curl = curl_init($method . '://' . $server . ':' . $port . $this->path);
829
+            $curl = curl_init($method.'://'.$server.':'.$port.$this->path);
830 830
             if ($keepAlive) {
831 831
                 $this->xmlrpc_curl_handle = $curl;
832 832
             }
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
         // results into variable
838 838
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
839 839
 
840
-        if ($this->debug > 1) {
840
+        if ($this->debug>1) {
841 841
             curl_setopt($curl, CURLOPT_VERBOSE, true);
842 842
             /// @todo allow callers to redirect curlopt_stderr to some stream which can be buffered
843 843
         }
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
             }
864 864
         }
865 865
         // extra headers
866
-        $headers = array('Content-Type: ' . $req->content_type, 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings));
866
+        $headers = array('Content-Type: '.$req->content_type, 'Accept-Charset: '.implode(',', $this->accepted_charset_encodings));
867 867
         // if no keepalive is wanted, let the server know it in advance
868 868
         if (!$keepAlive) {
869 869
             $headers[] = 'Connection: close';
@@ -880,15 +880,15 @@  discard block
 block discarded – undo
880 880
         curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
881 881
         // timeout is borked
882 882
         if ($timeout) {
883
-            curl_setopt($curl, CURLOPT_TIMEOUT, $timeout == 1 ? 1 : $timeout - 1);
883
+            curl_setopt($curl, CURLOPT_TIMEOUT, $timeout == 1 ? 1 : $timeout-1);
884 884
         }
885 885
 
886 886
         if ($username && $password) {
887
-            curl_setopt($curl, CURLOPT_USERPWD, $username . ':' . $password);
887
+            curl_setopt($curl, CURLOPT_USERPWD, $username.':'.$password);
888 888
             if (defined('CURLOPT_HTTPAUTH')) {
889 889
                 curl_setopt($curl, CURLOPT_HTTPAUTH, $authType);
890 890
             } elseif ($authType != 1) {
891
-                error_log('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported by the current PHP/curl install');
891
+                error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth is supported by the current PHP/curl install');
892 892
             }
893 893
         }
894 894
 
@@ -929,13 +929,13 @@  discard block
 block discarded – undo
929 929
             if ($proxyPort == 0) {
930 930
                 $proxyPort = 8080; // NB: even for HTTPS, local connection is on port 8080
931 931
             }
932
-            curl_setopt($curl, CURLOPT_PROXY, $proxyHost . ':' . $proxyPort);
932
+            curl_setopt($curl, CURLOPT_PROXY, $proxyHost.':'.$proxyPort);
933 933
             if ($proxyUsername) {
934
-                curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyUsername . ':' . $proxyPassword);
934
+                curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyUsername.':'.$proxyPassword);
935 935
                 if (defined('CURLOPT_PROXYAUTH')) {
936 936
                     curl_setopt($curl, CURLOPT_PROXYAUTH, $proxyAuthType);
937 937
                 } elseif ($proxyAuthType != 1) {
938
-                    error_log('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth to proxy is supported by the current PHP/curl install');
938
+                    error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth to proxy is supported by the current PHP/curl install');
939 939
                 }
940 940
             }
941 941
         }
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
         if (count($this->cookies)) {
947 947
             $cookieHeader = '';
948 948
             foreach ($this->cookies as $name => $cookie) {
949
-                $cookieHeader .= $name . '=' . $cookie['value'] . '; ';
949
+                $cookieHeader .= $name.'='.$cookie['value'].'; ';
950 950
             }
951 951
             curl_setopt($curl, CURLOPT_COOKIE, substr($cookieHeader, 0, -2));
952 952
         }
@@ -957,13 +957,13 @@  discard block
 block discarded – undo
957 957
 
958 958
         $result = curl_exec($curl);
959 959
 
960
-        if ($this->debug > 1) {
960
+        if ($this->debug>1) {
961 961
             $message = "---CURL INFO---\n";
962 962
             foreach (curl_getinfo($curl) as $name => $val) {
963 963
                 if (is_array($val)) {
964 964
                     $val = implode("\n", $val);
965 965
                 }
966
-                $message .= $name . ': ' . $val . "\n";
966
+                $message .= $name.': '.$val."\n";
967 967
             }
968 968
             $message .= "---END---";
969 969
             Logger::instance()->debugMessage($message);
@@ -973,7 +973,7 @@  discard block
 block discarded – undo
973 973
             /// @todo we should use a better check here - what if we get back '' or '0'?
974 974
 
975 975
             $this->errstr = 'no response';
976
-            $resp = new Response(0, PhpXmlRpc::$xmlrpcerr['curl_fail'], PhpXmlRpc::$xmlrpcstr['curl_fail'] . ': ' . curl_error($curl));
976
+            $resp = new Response(0, PhpXmlRpc::$xmlrpcerr['curl_fail'], PhpXmlRpc::$xmlrpcstr['curl_fail'].': '.curl_error($curl));
977 977
             curl_close($curl);
978 978
             if ($keepAlive) {
979 979
                 $this->xmlrpc_curl_handle = null;
@@ -1083,7 +1083,7 @@  discard block
 block discarded – undo
1083 1083
             $call['methodName'] = new Value($req->method(), 'string');
1084 1084
             $numParams = $req->getNumParams();
1085 1085
             $params = array();
1086
-            for ($i = 0; $i < $numParams; $i++) {
1086
+            for ($i = 0; $i<$numParams; $i++) {
1087 1087
                 $params[$i] = $req->getParam($i);
1088 1088
             }
1089 1089
             $call['params'] = new Value($params, 'array');
@@ -1109,15 +1109,15 @@  discard block
 block discarded – undo
1109 1109
             /// @todo test this code branch...
1110 1110
             $rets = $result->value();
1111 1111
             if (!is_array($rets)) {
1112
-                return false;       // bad return type from system.multicall
1112
+                return false; // bad return type from system.multicall
1113 1113
             }
1114 1114
             $numRets = count($rets);
1115 1115
             if ($numRets != count($reqs)) {
1116
-                return false;       // wrong number of return values.
1116
+                return false; // wrong number of return values.
1117 1117
             }
1118 1118
 
1119 1119
             $response = array();
1120
-            for ($i = 0; $i < $numRets; $i++) {
1120
+            for ($i = 0; $i<$numRets; $i++) {
1121 1121
                 $val = $rets[$i];
1122 1122
                 if (!is_array($val)) {
1123 1123
                     return false;
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
                 switch (count($val)) {
1126 1126
                     case 1:
1127 1127
                         if (!isset($val[0])) {
1128
-                            return false;       // Bad value
1128
+                            return false; // Bad value
1129 1129
                         }
1130 1130
                         // Normal return value
1131 1131
                         $response[$i] = new Response($val[0], 0, '', 'phpvals');
@@ -1153,19 +1153,19 @@  discard block
 block discarded – undo
1153 1153
 
1154 1154
             $rets = $result->value();
1155 1155
             if ($rets->kindOf() != 'array') {
1156
-                return false;       // bad return type from system.multicall
1156
+                return false; // bad return type from system.multicall
1157 1157
             }
1158 1158
             $numRets = $rets->count();
1159 1159
             if ($numRets != count($reqs)) {
1160
-                return false;       // wrong number of return values.
1160
+                return false; // wrong number of return values.
1161 1161
             }
1162 1162
 
1163 1163
             $response = array();
1164
-            foreach($rets as $val) {
1164
+            foreach ($rets as $val) {
1165 1165
                 switch ($val->kindOf()) {
1166 1166
                     case 'array':
1167 1167
                         if ($val->count() != 1) {
1168
-                            return false;       // Bad value
1168
+                            return false; // Bad value
1169 1169
                         }
1170 1170
                         // Normal return value
1171 1171
                         $response[] = new Response($val[0]);
Please login to merge, or discard this patch.