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

SimpleRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 48
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0
rs 10
1
<?php
2
3
namespace Addwiki\Mediawiki\Api\Client;
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
	private string $action;
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_STRING, expecting T_FUNCTION or T_CONST
Loading history...
17
18
	private array $params = [];
19
20
	private array $headers = [];
21
22
	/**
23
	 * @param string $action The API action.
24
	 * @param array $params The parameters for the action.
25
	 * @param array $headers Any extra HTTP headers to send.
26
	 *
27
	 * @throws InvalidArgumentException
28
	 */
29
	public function __construct( string $action, array $params = [], array $headers = [] ) {
30
		if ( !is_string( $action ) ) {
31
			throw new InvalidArgumentException( '$action must be string' );
32
		}
33
		$this->action = $action;
34
		$this->params = $params;
35
		$this->headers = $headers;
36
	}
37
38
	/**
39
	 * @return string[]
40
	 */
41
	public function getParams(): array {
42
		return array_merge( [ 'action' => $this->action ], $this->params );
43
	}
44
45
	/**
46
	 * @return string[]
47
	 */
48
	public function getHeaders(): array {
49
		return $this->headers;
50
	}
51
52
}
53