Request   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 93
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getUrl() 0 4 1
A getMethod() 0 4 1
A getBody() 0 4 1
A getHeaders() 0 4 1
1
<?php
2
3
namespace DominionEnterprises\Api;
4
use DominionEnterprises\Util;
5
6
/**
7
 * Concrete implementation of Request
8
 */
9
final class Request
10
{
11
    /**
12
     * The url for this request
13
     *
14
     * @var string
15
     */
16
    private $_url;
17
18
    /**
19
     * The HTTP method for this request
20
     *
21
     * @var string
22
     */
23
    private $_method;
24
25
    /**
26
     * The body for this request
27
     *
28
     * @var string
29
     */
30
    private $_body;
31
32
    /**
33
     * The HTTP headers for this request
34
     *
35
     * @var array
36
     */
37
    private $_headers;
38
39
    /**
40
     * Create a new request instance
41
     *
42
     * @param string $url
43
     * @param string $method
44
     * @param string|null $body
45
     * @param array $headers
46
     *
47
     * @throws \InvalidArgumentException Thrown if $url is not a non-empty string
48
     * @throws \InvalidArgumentException Thrown if $method is not a non-empty string
49
     * @throws \InvalidArgumentException Thrown if $body is not null or not a non-empty string
50
     */
51
    public function __construct($url, $method, $body = null, array $headers = [])
52
    {
53
        Util::throwIfNotType(['string' => [$url, $method]], true);
54
        Util::throwIfNotType(['string' => [$body]], true, true);
55
56
        $this->_url = $url;
57
        $this->_method = $method;
58
        $this->_body = $body;
59
        $this->_headers = $headers;
60
    }
61
62
    /**
63
     * Get the url of this request
64
     *
65
     * @return string
66
     */
67
    public function getUrl()
68
    {
69
        return $this->_url;
70
    }
71
72
    /**
73
     * Get the method of this request
74
     *
75
     * @return string
76
     */
77
    public function getMethod()
78
    {
79
        return $this->_method;
80
    }
81
82
    /**
83
     * Get the body of this request
84
     *
85
     * @return string
86
     */
87
    public function getBody()
88
    {
89
        return $this->_body;
90
    }
91
92
    /**
93
     * Get the headers of this request
94
     *
95
     * @return array
96
     */
97
    public function getHeaders()
98
    {
99
        return $this->_headers;
100
    }
101
}
102