Completed
Pull Request — master (#42)
by Chad
01:29
created

Request   A

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