@@ -14,8 +14,7 @@ public function __construct()
1414 {
1515 $ this ->apiHost = "https://codeclimate.com " ;
1616
17- if ( isset ($ _SERVER ["CODECLIMATE_API_HOST " ]) )
18- {
17+ if (isset ($ _SERVER ["CODECLIMATE_API_HOST " ])) {
1918 $ this ->apiHost = $ _SERVER ["CODECLIMATE_API_HOST " ];
2019 }
2120 }
@@ -27,7 +26,7 @@ public function __construct()
2726 *
2827 * @return \stdClass Response object with (code, message, headers & body properties)
2928 */
30- public function send ( $ json )
29+ public function send ($ json )
3130 {
3231 $ response = new \stdClass ;
3332 $ payload = (string )$ json ;
@@ -38,29 +37,25 @@ public function send( $json )
3837 'Host: codeclimate.com ' ,
3938 'Content-Type: application/json ' ,
4039 'User-Agent: Code Climate (PHP Test Reporter v ' . Version::VERSION . ') ' ,
41- 'Content-Length: ' . strlen ( $ payload ),
40+ 'Content-Length: ' . strlen ($ payload ),
4241 ],
4342 'content ' => $ payload ,
4443 "timeout " => 10 ,
4544 ],
4645 ];
47- $ context = stream_context_create ( $ options );
46+ $ context = stream_context_create ($ options );
4847 $ url = $ this ->apiHost . '/test_reports ' ;
4948
50- if ( $ stream = @fopen ( $ url , 'r ' , false , $ context ) )
51- {
52- $ meta = stream_get_meta_data ( $ stream );
53- $ rawResponse = implode ( "\r\n" , $ meta ['wrapper_data ' ] ) . "\r\n\r\n" . stream_get_contents ( $ stream );
54- fclose ( $ stream );
49+ if ($ stream = @fopen ($ url , 'r ' , false , $ context )) {
50+ $ meta = stream_get_meta_data ($ stream );
51+ $ rawResponse = implode ("\r\n" , $ meta ['wrapper_data ' ]) . "\r\n\r\n" . stream_get_contents ($ stream );
52+ fclose ($ stream );
5553
56- if ( !empty ($ rawResponse ) )
57- {
58- $ response = $ this ->buildResponse ( $ response , $ rawResponse );
54+ if (!empty ($ rawResponse )) {
55+ $ response = $ this ->buildResponse ($ response , $ rawResponse );
5956 }
60- }
61- else
62- {
63- $ response = $ this ->sendWithCurl ( $ url , $ payload );
57+ } else {
58+ $ response = $ this ->sendWithCurl ($ url , $ payload );
6459 }
6560
6661 return $ response ;
@@ -75,36 +70,33 @@ public function send( $json )
7570 *
7671 * @return \stdClass Response object with (code, message, headers & body properties)
7772 */
78- private function sendWithCurl ( $ url , $ payload )
73+ private function sendWithCurl ($ url , $ payload )
7974 {
8075 $ response = new \stdClass ;
81- $ curl = curl_init ( $ url );
82- curl_setopt ( $ curl , CURLOPT_HEADER , true );
83- curl_setopt ( $ curl , CURLOPT_RETURNTRANSFER , true );
84- curl_setopt ( $ curl , CURLOPT_CONNECTTIMEOUT , 10 );
76+ $ curl = curl_init ($ url );
77+ curl_setopt ($ curl , CURLOPT_HEADER , true );
78+ curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , true );
79+ curl_setopt ($ curl , CURLOPT_CONNECTTIMEOUT , 10 );
8580 curl_setopt (
8681 $ curl ,
8782 CURLOPT_HTTPHEADER ,
8883 [
8984 'Host: codeclimate.com ' ,
9085 'Content-Type: application/json ' ,
9186 'User-Agent: Code Climate (PHP Test Reporter v ' . Version::VERSION . ') ' ,
92- 'Content-Length: ' . strlen ( $ payload ),
87+ 'Content-Length: ' . strlen ($ payload ),
9388 ]
9489 );
95- curl_setopt ( $ curl , CURLOPT_CUSTOMREQUEST , 'POST ' );
96- curl_setopt ( $ curl , CURLOPT_POSTFIELDS , $ payload );
97- $ rawResponse = curl_exec ( $ curl );
90+ curl_setopt ($ curl , CURLOPT_CUSTOMREQUEST , 'POST ' );
91+ curl_setopt ($ curl , CURLOPT_POSTFIELDS , $ payload );
92+ $ rawResponse = curl_exec ($ curl );
9893
99- $ status = curl_getinfo ( $ curl , CURLINFO_HTTP_CODE );
100- if ( !empty ($ rawResponse ) )
101- {
102- $ response = $ this ->buildResponse ( $ response , $ rawResponse );
103- }
104- else
105- {
94+ $ status = curl_getinfo ($ curl , CURLINFO_HTTP_CODE );
95+ if (!empty ($ rawResponse )) {
96+ $ response = $ this ->buildResponse ($ response , $ rawResponse );
97+ } else {
10698 $ error = error_get_last ();
107- preg_match ( '/([0-9]{3})/ ' , $ error ['message ' ], $ match );
99+ preg_match ('/([0-9]{3})/ ' , $ error ['message ' ], $ match );
108100 $ errorCode = (isset ($ match [1 ])) ? $ match [1 ] : ($ status ? $ status : 500 );
109101
110102 $ response ->code = $ errorCode ;
@@ -124,11 +116,11 @@ private function sendWithCurl( $url, $payload )
124116 *
125117 * @return \stdClass Populated class object
126118 */
127- private function buildResponse ( $ response , $ body )
119+ private function buildResponse ($ response , $ body )
128120 {
129- list ($ response ->headers , $ response ->body ) = explode ( "\r\n\r\n" , $ body , 2 );
130- $ response ->headers = explode ( "\r\n" , $ response ->headers );
131- list (, $ response ->code , $ response ->message ) = explode ( ' ' , $ response ->headers [0 ], 3 );
121+ list ($ response ->headers , $ response ->body ) = explode ("\r\n\r\n" , $ body , 2 );
122+ $ response ->headers = explode ("\r\n" , $ response ->headers );
123+ list (, $ response ->code , $ response ->message ) = explode (' ' , $ response ->headers [0 ], 3 );
132124
133125 return $ response ;
134126 }
0 commit comments