NativeRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 25
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A reallyMakeRequest() 0 21 3
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