RequestResponse   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 73
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A set() 0 3 1
A has() 0 3 2
A get() 0 8 2
A getList() 0 3 1
A asJsonString() 0 3 1
1
<?php
2
3
namespace Onoi\HttpRequest;
4
5
use InvalidArgumentException;
6
7
/**
8
 * @license GNU GPL v2+
9
 * @since 1.1
10
 *
11
 * @author mwjames
12
 */
13
class RequestResponse {
14
15
	/**
16
	 * @var array
17
	 */
18
	private $fields = array();
19
20
	/**
21
	 * @since 1.1
22
	 */
23 7
	public function __construct( array $fields = array() ) {
24 7
		$this->fields = $fields;
25 7
	}
26
27
	/**
28
	 * @since 1.1
29
	 *
30
	 * @param string $key
31
	 * @param mixed $value
32
	 */
33 2
	public function set( $key, $value ) {
34 2
		$this->fields[$key] = $value;
35 2
	}
36
37
	/**
38
	 * @since 1.1
39
	 *
40
	 * @param string $key
41
	 *
42
	 * @return boolean
43
	 */
44 3
	public function has( $key ) {
45 3
		return isset( $this->fields[$key] ) || array_key_exists( $key, $this->fields );
46
	}
47
48
	/**
49
	 * @since 1.1
50
	 *
51
	 * @param string $key
52
	 *
53
	 * @return string
54
	 * @throws InvalidArgumentException
55
	 */
56 3
	public function get( $key ) {
57
58 3
		if ( $this->has( $key ) ) {
59 2
			return $this->fields[$key];
60
		}
61
62 1
		throw new InvalidArgumentException( "{$key} is an unregistered option" );
63
	}
64
65
	/**
66
	 * @since 1.1
67
	 *
68
	 * @return array
69
	 */
70 1
	public function getList() {
71 1
		return $this->fields;
72
	}
73
74
	/**
75
	 * @since 1.4
76
	 *
77
	 * @param integer $flags
78
	 *
79
	 * @return string
80
	 */
81 1
	public function asJsonString( $flags = 0 ) {
82 1
		return json_encode( $this->fields, $flags );
83
	}
84
85
}
86