@@ -14,8 +14,7 @@ public function __construct()
14
14
{
15
15
$ this ->apiHost = "https://codeclimate.com " ;
16
16
17
- if ( isset ($ _SERVER ["CODECLIMATE_API_HOST " ]) )
18
- {
17
+ if (isset ($ _SERVER ["CODECLIMATE_API_HOST " ])) {
19
18
$ this ->apiHost = $ _SERVER ["CODECLIMATE_API_HOST " ];
20
19
}
21
20
}
@@ -27,7 +26,7 @@ public function __construct()
27
26
*
28
27
* @return \stdClass Response object with (code, message, headers & body properties)
29
28
*/
30
- public function send ( $ json )
29
+ public function send ($ json )
31
30
{
32
31
$ response = new \stdClass ;
33
32
$ payload = (string )$ json ;
@@ -38,29 +37,25 @@ public function send( $json )
38
37
'Host: codeclimate.com ' ,
39
38
'Content-Type: application/json ' ,
40
39
'User-Agent: Code Climate (PHP Test Reporter v ' . Version::VERSION . ') ' ,
41
- 'Content-Length: ' . strlen ( $ payload ),
40
+ 'Content-Length: ' . strlen ($ payload ),
42
41
],
43
42
'content ' => $ payload ,
44
43
"timeout " => 10 ,
45
44
],
46
45
];
47
- $ context = stream_context_create ( $ options );
46
+ $ context = stream_context_create ($ options );
48
47
$ url = $ this ->apiHost . '/test_reports ' ;
49
48
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 );
55
53
56
- if ( !empty ($ rawResponse ) )
57
- {
58
- $ response = $ this ->buildResponse ( $ response , $ rawResponse );
54
+ if (!empty ($ rawResponse )) {
55
+ $ response = $ this ->buildResponse ($ response , $ rawResponse );
59
56
}
60
- }
61
- else
62
- {
63
- $ response = $ this ->sendWithCurl ( $ url , $ payload );
57
+ } else {
58
+ $ response = $ this ->sendWithCurl ($ url , $ payload );
64
59
}
65
60
66
61
return $ response ;
@@ -75,36 +70,33 @@ public function send( $json )
75
70
*
76
71
* @return \stdClass Response object with (code, message, headers & body properties)
77
72
*/
78
- private function sendWithCurl ( $ url , $ payload )
73
+ private function sendWithCurl ($ url , $ payload )
79
74
{
80
75
$ 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 );
85
80
curl_setopt (
86
81
$ curl ,
87
82
CURLOPT_HTTPHEADER ,
88
83
[
89
84
'Host: codeclimate.com ' ,
90
85
'Content-Type: application/json ' ,
91
86
'User-Agent: Code Climate (PHP Test Reporter v ' . Version::VERSION . ') ' ,
92
- 'Content-Length: ' . strlen ( $ payload ),
87
+ 'Content-Length: ' . strlen ($ payload ),
93
88
]
94
89
);
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 );
98
93
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 {
106
98
$ error = error_get_last ();
107
- preg_match ( '/([0-9]{3})/ ' , $ error ['message ' ], $ match );
99
+ preg_match ('/([0-9]{3})/ ' , $ error ['message ' ], $ match );
108
100
$ errorCode = (isset ($ match [1 ])) ? $ match [1 ] : ($ status ? $ status : 500 );
109
101
110
102
$ response ->code = $ errorCode ;
@@ -124,11 +116,11 @@ private function sendWithCurl( $url, $payload )
124
116
*
125
117
* @return \stdClass Populated class object
126
118
*/
127
- private function buildResponse ( $ response , $ body )
119
+ private function buildResponse ($ response , $ body )
128
120
{
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 );
132
124
133
125
return $ response ;
134
126
}
0 commit comments