FluentRequest::factory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Mediawiki\Api;
4
5
/**
6
 * @since 1.0
7
 *
8
 * @author Addshore
9
 */
10
class FluentRequest implements Request {
11
12
	/**
13
	 * @var array
14
	 */
15
	private $params = [];
16
17
	/**
18
	 * @var array
19
	 */
20
	private $headers = [];
21
22
	/**
23
	 * @since 1.0
24
	 *
25
	 * @return array
26
	 */
27 7
	public function getParams() {
28 7
		return $this->params;
29
	}
30
31
	/**
32
	 * @since 1.0
33
	 *
34
	 * @return array
35
	 */
36 2
	public function getHeaders() {
37 2
		return $this->headers;
38
	}
39
40
	/**
41
	 * @since 1.0
42
	 *
43
	 * @return static
44
	 */
45 1
	public static function factory() {
46 1
		return new static();
47
	}
48
49
	/**
50
	 * @since 1.0
51
	 *
52
	 * @param string $action The action name.
53
	 *
54
	 * @return $this
55
	 */
56 1
	public function setAction( $action ) {
57 1
		$this->setParam( 'action', $action );
58 1
		return $this;
59
	}
60
61
	/**
62
	 * Totally overwrite any previously set params
63
	 *
64
	 * @since 1.0
65
	 *
66
	 * @param array $params New parameters.
67
	 *
68
	 * @return $this
69
	 */
70 1
	public function setParams( array $params ) {
71 1
		$this->params = $params;
72 1
		return $this;
73
	}
74
75
	/**
76
	 * Totally overwrite any previously set params
77
	 *
78
	 * @since 1.0
79
	 *
80
	 * @param array $params Additional parameters.
81
	 *
82
	 * @return $this
83
	 */
84 1
	public function addParams( array $params ) {
85 1
		$this->params = array_merge( $this->params, $params );
86 1
		return $this;
87
	}
88
89
	/**
90
	 * Set a single parameter.
91
	 *
92
	 * @since 1.0
93
	 *
94
	 * @param string $param The parameter name.
95
	 * @param string $value The parameter value.
96
	 *
97
	 * @return $this
98
	 */
99 3
	public function setParam( $param, $value ) {
100 3
		$this->params[$param] = $value;
101 3
		return $this;
102
	}
103
104
	/**
105
	 * Totally overwrite any previously set HTTP headers.
106
	 *
107
	 * @since 1.0
108
	 *
109
	 * @param array $headers New headers.
110
	 *
111
	 * @return $this
112
	 */
113 1
	public function setHeaders( $headers ) {
114 1
		$this->headers = $headers;
115 1
		return $this;
116
	}
117
118
}
119