SimpleRequest::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
1
<?php
2
3
namespace Mediawiki\Api;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Please consider using a FluentRequest object
9
 *
10
 * @since 0.2
11
 *
12
 * @author Addshore
13
 */
14
class SimpleRequest implements Request {
15
16
	/**
17
	 * @var string
18
	 */
19
	private $action;
20
21
	/**
22
	 * @var array
23
	 */
24
	private $params;
25
26
	/**
27
	 * @var array
28
	 */
29
	private $headers;
30
31
	/**
32
	 * @param string $action The API action.
33
	 * @param array $params The parameters for the action.
34
	 * @param array $headers Any extra HTTP headers to send.
35
	 *
36
	 * @throws InvalidArgumentException
37
	 */
38 7
	public function __construct( $action, array $params = [], array $headers = [] ) {
39 7
		if ( !is_string( $action ) ) {
40 1
			throw new InvalidArgumentException( '$action must be string' );
41
		}
42 6
		$this->action = $action;
43 6
		$this->params = $params;
44 6
		$this->headers = $headers;
45 6
	}
46
47
	/**
48
	 * @return string[]
49
	 */
50 6
	public function getParams() {
51 6
		return array_merge( [ 'action' => $this->action ], $this->params );
52
	}
53
54
	/**
55
	 * @return string[]
56
	 */
57 6
	public function getHeaders() {
58 6
		return $this->headers;
59
	}
60
61
}
62