NativeRequest::reallyMakeRequest()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 14
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 21
rs 9.7998
1
<?php declare( strict_types=1 );
2
3
namespace BotRiconferme\Request;
4
5
/**
6
 * Request done via file_get_contents, when cURL isn't available
7
 */
8
class NativeRequest extends RequestBase {
9
	/**
10
	 * @inheritDoc
11
	 */
12
	protected function reallyMakeRequest( string $params ): string {
13
		$context = [
14
			'http' => [
15
				'method' => $this->method,
16
				'header' => $this->buildHeadersString( $this->getHeaders() )
17
			]
18
		];
19
		$url = $this->url;
20
		if ( $this->method === self::METHOD_POST ) {
21
			$context['http']['content'] = $params;
22
		} else {
23
			$url = "$url?$params";
24
		}
25
		$context = stream_context_create( $context );
26
		$body = file_get_contents( $url, false, $context );
27
28
		foreach ( $http_response_header as $header ) {
29
			$this->handleResponseHeader( $header );
30
		}
31
32
		return $body;
33
	}
34
}
35