ClientTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 90
c 0
b 0
f 0
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A patch() 0 3 1
A post() 0 3 1
A head() 0 3 1
A put() 0 3 1
A delete() 0 3 1
1
<?php
2
3
namespace EasyHttp\Traits;
4
5
use EasyHttp\Model\HttpOptions;
6
use EasyHttp\Model\HttpResponse;
7
8
/**
9
 * ClientTrait class
10
 *
11
 * @link    https://github.com/shahradelahi/easy-http
12
 * @author  Shahrad Elahi (https://github.com/shahradelahi)
13
 * @license https://github.com/shahradelahi/easy-http/blob/master/LICENSE (MIT License)
14
 */
15
trait ClientTrait
16
{
17
18
	/**
19
	 * Create and send an HTTP request.
20
	 *
21
	 * @param string $method HTTP method.
22
	 * @param string $uri URI object or string.
23
	 * @param HttpOptions|array $options Request options to apply.
24
	 *
25
	 * @return HttpResponse
26
	 */
27
	abstract public function request(string $method, string $uri, HttpOptions|array $options = []): HttpResponse;
28
29
	/**
30
	 * Create and send an HTTP GET request.
31
	 *
32
	 * @param string $uri URI object or string.
33
	 * @param HttpOptions|array $options Request options to apply.
34
	 *
35
	 * @return HttpResponse
36
	 */
37
	public function get(string $uri, HttpOptions|array $options = []): HttpResponse
38
	{
39
		return $this->request('GET', $uri, $options);
40
	}
41
42
	/**
43
	 * Create and send an HTTP HEAD request.
44
	 *
45
	 * @param string $uri URI object or string.
46
	 * @param HttpOptions|array $options Request options to apply.
47
	 *
48
	 * @return HttpResponse
49
	 */
50
	public function head(string $uri, HttpOptions|array $options = []): HttpResponse
51
	{
52
		return $this->request('HEAD', $uri, $options);
53
	}
54
55
	/**
56
	 * Create and send an HTTP PUT request.
57
	 *
58
	 * @param string $uri URI object or string.
59
	 * @param HttpOptions|array $options Request options to apply.
60
	 *
61
	 * @return HttpResponse
62
	 */
63
	public function put(string $uri, HttpOptions|array $options = []): HttpResponse
64
	{
65
		return $this->request('PUT', $uri, $options);
66
	}
67
68
	/**
69
	 * Create and send an HTTP POST request.
70
	 *
71
	 * @param string $uri URI object or string.
72
	 * @param HttpOptions|array $options Request options to apply.
73
	 *
74
	 * @return HttpResponse
75
	 */
76
	public function post(string $uri, HttpOptions|array $options = []): HttpResponse
77
	{
78
		return $this->request('POST', $uri, $options);
79
	}
80
81
	/**
82
	 * Create and send an HTTP PATCH request.
83
	 *
84
	 * @param string $uri URI object or string.
85
	 * @param HttpOptions|array $options Request options to apply.
86
	 *
87
	 * @return HttpResponse
88
	 */
89
	public function patch(string $uri, HttpOptions|array $options = []): HttpResponse
90
	{
91
		return $this->request('PATCH', $uri, $options);
92
	}
93
94
	/**
95
	 * Create and send an HTTP DELETE request.
96
	 *
97
	 * @param string $uri URI object or string.
98
	 * @param HttpOptions|array $options Request options to apply.
99
	 *
100
	 * @return HttpResponse
101
	 */
102
	public function delete(string $uri, HttpOptions|array $options = []): HttpResponse
103
	{
104
		return $this->request('DELETE', $uri, $options);
105
	}
106
107
}