Completed
Push — main ( 26c7b4...5ab5c5 )
by
unknown
04:18
created

FluentRequest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 109
c 0
b 0
f 0
wmc 8
lcom 1
cbo 0
rs 10
1
<?php
2
3
namespace Addwiki\Mediawiki\Api\Client;
4
5
/**
6
 * @since 1.0
7
 *
8
 * @author Addshore
9
 */
10
class FluentRequest implements Request {
11
12
	private array $params = [];
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
13
14
	private array $headers = [];
15
16
	/**
17
	 * @since 1.0
18
	 *
19
	 * @return array
20
	 */
21
	public function getParams(): array {
22
		return $this->params;
23
	}
24
25
	/**
26
	 * @since 1.0
27
	 *
28
	 * @return array
29
	 */
30
	public function getHeaders(): array {
31
		return $this->headers;
32
	}
33
34
	/**
35
	 * @since 1.0
36
	 *
37
	 * @return static
38
	 */
39
	public static function factory() {
40
		return new static();
41
	}
42
43
	/**
44
	 * @since 1.0
45
	 *
46
	 * @param string $action The action name.
47
	 *
48
	 * @return $this
49
	 */
50
	public function setAction( string $action ): self {
51
		$this->setParam( 'action', $action );
52
		return $this;
53
	}
54
55
	/**
56
	 * Totally overwrite any previously set params
57
	 *
58
	 * @since 1.0
59
	 *
60
	 * @param array $params New parameters.
61
	 *
62
	 * @return $this
63
	 */
64
	public function setParams( array $params ): self {
65
		$this->params = $params;
66
		return $this;
67
	}
68
69
	/**
70
	 * Totally overwrite any previously set params
71
	 *
72
	 * @since 1.0
73
	 *
74
	 * @param array $params Additional parameters.
75
	 *
76
	 * @return $this
77
	 */
78
	public function addParams( array $params ): self {
79
		$this->params = array_merge( $this->params, $params );
80
		return $this;
81
	}
82
83
	/**
84
	 * Set a single parameter.
85
	 *
86
	 * @since 1.0
87
	 *
88
	 * @param string $param The parameter name.
89
	 * @param string $value The parameter value.
90
	 *
91
	 * @return $this
92
	 */
93
	public function setParam( string $param, string $value ): self {
94
		$this->params[$param] = $value;
95
		return $this;
96
	}
97
98
	/**
99
	 * Totally overwrite any previously set HTTP headers.
100
	 *
101
	 * @since 1.0
102
	 *
103
	 * @param array $headers New headers.
104
	 *
105
	 * @return $this
106
	 */
107
	public function setHeaders( array $headers ): self {
108
		$this->headers = $headers;
109
		return $this;
110
	}
111
112
}
113